Skip to content

creating custom thunk middleware #66

@necolas

Description

@necolas

Any interest in supporting more complex use cases for thunks (like injecting an API client)?

const export myAction = (data) => (dispatch, getState, helpers) => {
  return helpers.client.get(PATH, options).then(doStuff);
}

Doesn't need to be a breaking change; we can export a factory:

export const createThunkMiddleware = (any) => ({ dispatch, getState }) => next => action => {
  if (typeof action === 'function') {
    return action(dispatch, getState, any);
  }
  return next(action);
};

export default createThunkMiddleware();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions