Redux-Thunk-dispatch multi actions one by one
文章目录

Redux 里面 dispatch 多个 action, 其实很简单:

先 dispatch 一个 非延时操作, 然后 return 一个 thunk

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
export const setting_toggleAutoSave = autoSave => (dispatch, getState) => {
dispatch({
type: 'SETTING_CHANGE_AUTOSAVE',
autoSave,
});
return dispatch(setting_write());
};

export const setting_write = () => (dispatch, getState) => {
console.log('setting.write', getState().app.settings);
FileSystem.writeAsStringAsync(
`${FileSystem.documentDirectory}setting.json` ,
JSON.stringify(getState().app.settings)
);
};