应用程序:道具类型“商店”无效;它必须是一个函数,通常来自 `prop-types` 包,但接收到 `undefined`
App: prop type `store` is invalid; it must be a function, usually from the `prop-types` package, but received `undefined`
我对 mobx 应用程序有反应,但在控制台中收到以下错误消息:
App: prop type store
is invalid; it must be a function, usually from
the prop-types
package, but received undefined
代码如下所示:
import React, {PureComponent} from 'react';
import {observer, PropTypes} from 'mobx-react';
// Some other imports
const propTypes = {
store: PropTypes.object
};
@observer
class App extends PureComponent {
// Some lifecycle and class functions here
render() {
// Render implementation here
}
}
App.propTypes = propTypes;
export default App;
index.js
文件如下所示:
// Some imports here...
ReactDOM.render(<App store={store} />, document.getElementById('root'));
不确定我做错了什么。
mobx-react
exports 仅在特定于 mobx 的 PropTypes 类型中。
因此,要使用 React PropTypes,请像往常一样尝试从 prop-types
包中导入它们:
import PropTypes from 'prop-types';
import {PropTypes as MobxPropTypes} from 'mobx-react';
然后如果你需要使用 Mobx 的类型,你可以使用 MobxPropTypes
我对 mobx 应用程序有反应,但在控制台中收到以下错误消息:
App: prop type
store
is invalid; it must be a function, usually from theprop-types
package, but receivedundefined
代码如下所示:
import React, {PureComponent} from 'react';
import {observer, PropTypes} from 'mobx-react';
// Some other imports
const propTypes = {
store: PropTypes.object
};
@observer
class App extends PureComponent {
// Some lifecycle and class functions here
render() {
// Render implementation here
}
}
App.propTypes = propTypes;
export default App;
index.js
文件如下所示:
// Some imports here...
ReactDOM.render(<App store={store} />, document.getElementById('root'));
不确定我做错了什么。
mobx-react
exports 仅在特定于 mobx 的 PropTypes 类型中。
因此,要使用 React PropTypes,请像往常一样尝试从 prop-types
包中导入它们:
import PropTypes from 'prop-types';
import {PropTypes as MobxPropTypes} from 'mobx-react';
然后如果你需要使用 Mobx 的类型,你可以使用 MobxPropTypes