Skip to content

Instantly share code, notes, and snippets.

@zzdjk6
Created February 13, 2020 09:27
Show Gist options
  • Save zzdjk6/d11893aac2164ee6ed6eb10151811f68 to your computer and use it in GitHub Desktop.
Save zzdjk6/d11893aac2164ee6ed6eb10151811f68 to your computer and use it in GitHub Desktop.
// Imagine we defined a thunk action creator from routine
const fetchData = getThunkActionCreator(fetchDataRoutine, async (id: number) => {
return await api.fetchData(id);
});
// We could write another thunk action creator to access the existing state
const fetchDataWithIdFromState = () => (dispatch: Dispatch, getState: () => RootState) => {
const id = getState().somewhere.id;
return dispatch(fetchData(id));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment