Skip to content

Q: how to avoid exposing actionCreators when using redux-thunk #201

Closed
@NickSevens

Description

@NickSevens

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions