我对Redux非常陌生,请耐心等待我的翻译。我的朋友建议我不要将axios调用放在componentDidMount()
里面,而是将它们放在一个action文件中。以下是代码片段:
componentDidMount() {
axios.get('http://xxxx/customers').then(res => {
this.setState({
res,
customer: res.data
})
})
axios.get('http://xxxx/events').then(res => {
this.setState({
res,
event: res.data
})
})
axios.get('http://xxxx/locks').then(res => {
this.setState({
res,
lock: res.data
})
})
}
我知道要改变应用程序的状态,需要派发一个动作(action):
但问题是,我不确定如何设置所有这些。如果有人有一些技巧,我会非常乐意接受。