react-hook-thunk-reducer icon indicating copy to clipboard operation
react-hook-thunk-reducer copied to clipboard

Support injecting a custom argument

Open jednano opened this issue 6 years ago • 5 comments

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));
};

jednano avatar Jul 06 '19 22:07 jednano

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 avatar Jul 08 '19 00:07 nathanbuchar

PRs are also welcome!

nathanbuchar avatar Jul 08 '19 00:07 nathanbuchar

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

dsfx3d avatar Jul 14 '19 21:07 dsfx3d

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 avatar Jul 16 '19 05:07 nathanbuchar

You might also consider the solution described in #10

nathanbuchar avatar Sep 09 '19 17:09 nathanbuchar