nathanbuchar / react-hook-thunk-reducer

📡 A React useReducer() hook whose dispatcher supports thunks à la redux-thunk.
MIT License
108 stars 14 forks source link

Support injecting a custom argument #9

Open jednano opened 5 years ago

jednano commented 5 years ago

Redux-thunk has a feature where you can inject a custom argument.

I think this library can support the same feature if it were implemented like so:

helpers/useThunkReducer.js

import { withExtraArgument } from 'react-hook-thunk-reducer';

import BrowserApp from '../BrowserApp';

export default withExtraArgument({ app: new BrowserApp() });

An implementation of this might look like thus:

const saveData = (dispatch, getState, { app }) => {
  app.localStorage.setItem('data', JSON.stringify(data));
};
nathanbuchar commented 5 years ago

Hey @jedmao, thanks for the suggestion! I remember seeing this when I was building out this module and using redux thunk as a reference. However, for the first release I wanted to keep things simple. I'll certainly consider adding this in in future :)

nathanbuchar commented 5 years ago

PRs are also welcome!

dsfx3d commented 5 years ago

If no one's working on it. Can I create a PR?

nathanbuchar commented 5 years ago

I've experimented with this and I didn't find a solution I was totally happy with. It would be very helpful to see other approaches and maybe we can work together for a common solution (: definitely give it a shot

nathanbuchar commented 5 years ago

You might also consider the solution described in #10