Reactjs App:道具类型'store'无效;它必须是一个函数,通常来自'prop types'包,但收到'undefined'`
我有一个react with mobx应用程序,我在控制台中收到以下错误消息: App:prop typeReactjs App:道具类型'store'无效;它必须是一个函数,通常来自'prop types'包,但收到'undefined'`,reactjs,mobx,react-proptypes,Reactjs,Mobx,React Proptypes,我有一个react with mobx应用程序,我在控制台中收到以下错误消息: App:prop typestore无效;它必须是一个函数,通常来自 道具类型包,但收到的未定义 代码如下所示: import React, {PureComponent} from 'react'; import {observer, PropTypes} from 'mobx-react'; // Some other imports const propTypes = { store: PropTy
store
无效;它必须是一个函数,通常来自
道具类型
包,但收到的未定义
代码如下所示:
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'));
//此处有些导入。。。
ReactDOM.render(,document.getElementById('root'));
不确定我做错了什么。mobx只在特定于mobx的PropTypes中作出反应
因此,要使用React PropTypes,请尝试像往常一样从prop types
包导入它们:
import PropTypes from 'prop-types';
import {PropTypes as MobxPropTypes} from 'mobx-react';
然后,如果需要使用Mobx中的类型,可以使用MobxPropTypes
React。不推荐使用PropTypes
<代码>道具类型
包装是一种选择<代码>从“道具类型”导入道具类型@cfraser-事实上,这是我最后必须做的事情。iofjuupasli-想更新答案以便我接受吗?