在控制台中使用 redux-form fieldInputPropTypes 抛出错误

Using redux-form fieldInputPropTypes throwing error in console

我在项目中使用 redux-form,想使用 fieldInputPropTypes,可以从 redux-form 导入。我是这样用的

import { fieldInputPropTypes } from 'redux-form';
...
SuperComponent.propTypes = {
  ...
  input: fieldInputPropTypes.isRequired,
  ...
};

但是我在控制台中收到错误消息: Warning: Failed prop type: SuperComponent: prop type ``input`` is invalid; it must be a function, usually from React.PropTypes.

我是不是用错了?

您应该将其包装在 'prop-types' 包的 PropTypes.shape() 中。

查看来源here

工作示例:

import PropTypes from 'prop-types';
import { fieldInputPropTypes } from 'redux-form';
...
SuperComponent.propTypes = {
  ...
  input: PropTypes.shape(fieldInputPropTypes).isRequired,
  ...
};