Reactjs 在Redux中使用异步数据初始化状态
我想在创建状态时通过AJAX填充两个令牌属性。Redux似乎没有太多关于这方面的文档。我不能使用componentWillMount来实现这一点,因为我设置容器的方式根本不起作用Reactjs 在Redux中使用异步数据初始化状态,reactjs,react-native,redux,react-redux,Reactjs,React Native,Redux,React Redux,我想在创建状态时通过AJAX填充两个令牌属性。Redux似乎没有太多关于这方面的文档。我不能使用componentWillMount来实现这一点,因为我设置容器的方式根本不起作用 const Auth = Record({ token: '', yelpToken: '', }); 在调用createStore之前是否会运行函数? 您可以用以下内容替换索引: class EntryPoint extends Components { constructor(){
const Auth = Record({
token: '',
yelpToken: '',
});
在调用createStore之前是否会运行函数?
您可以用以下内容替换索引:
class EntryPoint extends Components {
constructor(){
this.state = {
//can be replaced with store state..
finishedFetching: false
}
}
componentDidMount() {
//you can chain dispatches with redux thunk
dispatch(fetchAsyncData())
.then(() => this.setState({finishedFetching: true}))
}
render() {
return this.state.finishedFetching ? <App/> : null;
}
}
要在创建存储时进行ajax调用,并在渲染之前填充这两个字段吗?这是在服务器端渲染上下文中还是在客户端上?