React native 异步redux thunk需要wrapoer函数
我的redux thunk需要一个包装器函数。(我开玩笑的商店不需要它) Thunk作为中间件添加到我的商店中 有效的行动:React native 异步redux thunk需要wrapoer函数,react-native,redux,react-redux,redux-thunk,React Native,Redux,React Redux,Redux Thunk,我的redux thunk需要一个包装器函数。(我开玩笑的商店不需要它) Thunk作为中间件添加到我的商店中 有效的行动: export function getSettings (establishmentId: string) { return (dispatch: any) => { return () => { dispatch(settingsLoading()) Client
export function getSettings (establishmentId: string) {
return (dispatch: any) => {
return () => {
dispatch(settingsLoading())
Client
.getSettings(establishmentId)
.then((settings: ISettings) => {
dispatch(getSettingsSuccess(settings))
})
}
}
}
派遣:
dispatch(getSettings(机构ID))
不起作用的操作(但在我的玩笑测试中确实起作用):
当我不使用包装器函数时,它告诉我应该应用thunk中间件(我已经应用了)
找到答案后,我们在mapDispatchToProps中犯了一个错误,使用了BindActionCreator的组合,只返回了一个对象列表:
const mapDispatchToProps = (dispatch: any) => bindActionCreators(
{
getSettings: (establishmentId: string) => dispatch(getSettings(establishmentId))
},
dispatch
)
应该是:
const mapDispatchToProps = (dispatch: any) => {
getSettings: (establishmentId: string) => dispatch(getSettings(establishmentId))
}
你能澄清一下“不起作用”吗?您显示的第二个代码段应该是正确的。它抛出了一个错误,即我应该为异步操作安装thunk中间件。这可以简化为使用
const-mapDispatch={getSettings}
。
const mapDispatchToProps = (dispatch: any) => bindActionCreators(
{
getSettings: (establishmentId: string) => dispatch(getSettings(establishmentId))
},
dispatch
)
const mapDispatchToProps = (dispatch: any) => {
getSettings: (establishmentId: string) => dispatch(getSettings(establishmentId))
}