0
我打电话给getLocalToken从我的组件读取字符串的操作从AsyncStorage。以下是我如何调用该函数。动作必须是普通物体。使用自定义中间件进行异步功能。 React Native
componentWillMount() {
this.props.getLocalToken();
console.log("CWM", this.props.auth);
}
以下是我的行动
export const getLocalToken = async() => {
try {
const localToken = await AsyncStorage.getItem('@auth:localToken');
const mobileNumber = await AsyncStorage.getItem('@auth:mobileNumber');
}
catch (e) {
console.log('Failed to read token', e);
}
return (dispatch) => {
console.log("get token");
dispatch({
type: types.GET_LOCALTOKEN_SUCCESS,
payload: { localToken: this.localToken, mobileNumber: this.mobileNumber }
});
}
}
对于这个代码,我得到行动必须是纯对象。使用自定义中间件进行异步功能。错误。
错误消息似乎很自我描述,什么似乎是问题? – Nit
我无法弄清楚,因为我是Javascript和React Native的新手 –
要更改错误消息,默认操作不支持异步操作。如果你想让你的动作异步,你将需要使用自定义中间件,一个常用的选项是[Redux Thunk](https://github.com/gaearon/redux-thunk)。 – Nit