Q: how to avoid exposing actionCreators when using redux-thunk
NickSevens opened this issue · 0 comments
Hello,
I'm using createAsyncAction
to create my async actions.
Then, I create another function using redux-thunk
to actually perform those actions alltogether.
This leaves me with a confusing export list in my actions.ts (for example) file.
For example, autocomplete suggests me both the action generator and the action executor functions when trying to use it in my container components.
I can't seem to find a way to tie everything together without exporting all functions everywhere...
For example:
export const fetchTeamsAsync = createAsyncAction(
"@@teams/FETCH_TEAMS_REQUEST",
"@@teams/FETCH_TEAMS_SUCCESS",
"@@teams/FETCH_TEAMS_FAILURE",
"@@teams/FETCH_TEAMS_CANCELLED"
)<
[undefined, CancellableStartMeta],
[NormalizedSchema<any, string[]>, CancellableEndMeta],
[Error, CancellableEndMeta],
[undefined, CancellableEndMeta]
>();
export const execFetchTeamsAsync = () => async (
dispatch: Dispatch,
getState: () => Types.RootState
): Promise<void> => {
// fetch data, dispatch request, success, failure, etc...
};
In my reducer, I use the createReducer()
and handleAction
functions, which need the exported fetchTeamsAsync variable.
createReducer(initialState.currentItems).handleAction(fetchTeamsAsync.success, (state, action) => state);
So, essentially I was wondering if there is a way of only exporting the executing function, since this is the only one that needs to be exposed to my container components.
Any help would be appreciated.