我是新来的反应者和redux者,所以很困惑在哪里用伪数据初始化存储? 我在根组件中使用provider。 访问我发现的商店的唯一两种方法是使用以下方法:-
Provider.childContextTypes = {
store: React.PropTypes.object
}
或使用connect,
const mapStateToProps = state => ({
state:state.contacts
});
const mapDispatchToProps = dispatch => ({
setDummyData: () => dispatch(setDummyData())
});
export default connect(
mapStateToProps,
mapDispatchToProps
)(ComponentName)
但是联系人尚未初始化..如何处理?
我可以找到带有连接和虚拟数据示例的任何链接都将非常有帮助
在整个商店的createStore
中或每个切片的reducer中进行。
您可以在index.js
文件中初始化store
(例如,如果使用过create-react-app
)。 初始化商店后,可以将其传递给提供者,并用提供者包装您的应用程序:
const = createStore(someReducers, someMiddleWareIfYouHaveIt)
<Provider store={store}>
<App />
</Provider>
有一些入门套件这里的ReactJS网站上为好。