我已经实现了 redux-thunk,它在我的 react-native 应用程序中运行良好。我有一些“this.counterValue”,在从 api 获得响应后必须更新该值。由于 api 获取方法在另一个动作文件中实现,并且在该文件中实现响应。那么,必须如何实现才能使这项工作正常进行。我不希望“this.counterValue”中的更改导致我的应用程序重新呈现。我是本地人的新手,能得到帮助会很棒。谢谢。
组件文件:
this.counterValue = 75; //local variable
this.props.fetchData('onStart'); // call to fetch data from actions files
动作文件:
export const fetchData = (fetchType) => {
return async dispatch => {
dispatch(fetchingDataRequest());
fetch(AllApi),
{
method: 'GET',
headers:
{
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': 'Bearer '+ global.apiToken,
},
})
.then(response => {
return response.json()
})
.then(RetrivedData => {
dispatch(fetchingDataSuccess(RetrivedData.data));
})
.catch(error => {
dispatch(fetchingNotificationFailure(error));
});
}
}