Easy-peasy: need context export

Created on 23 Jan 2019  路  10Comments  路  Source: ctrlplusb/easy-peasy

Hello,

I need the ability to import context object to use with https://github.com/supasate/connected-react-router
wich rely by default on ReactReduxContext from react-redux but offer the possibility to provide a custom context and in this case, I need the one from easy-peasy.
Could you please just export it.
Many thanks (and also for making this great library).

Most helpful comment

Maybe it is not a problem to provide two contexts, one from react-redux:

import { Provider } from 'react-redux'
import { StoreProvider } from 'easy-peasy';
export default hot(() => <StoreProvider store={store} ><Provider store={store} >
    <ConnectedRouter history={history}> { /* place ConnectedRouter under Provider */ }
      { /* your usual react-router v4 routing */ }
    </ConnectedRouter>
  </Provider></StoreProvider>)

where both referencing same store.

All 10 comments

I recommend using an alternative lib that doesn't make you depend on react-redux.

Discussed here:
https://github.com/ctrlplusb/easy-peasy/issues/25#issuecomment-438053615

The problem is not react-redux, it's not using it, the problem is that this lib expect to extract store from a context consumer, so I have to provide the context object of easy-peasy, and that could be the case for others libraries too.
By the way, I don't know another library that connect react router to redux and I don't want to reinvent the wheel. Can you tell me what is your recommandation ?

Well, they are depending on the context that is provided by the react-redux library. 馃榾So even if we exposed the context from easy-peasy it probably wouldn't work with libraries that were expecting the react-redux context (I think).

Good news though! There are alternatives available. 馃榾

As stated in the comment I linked to above you can use redux-first-history. I've used it myself with this library and it's great. 馃憤

I was just lookin on redux-first-history, thank you for the confirmation that is your recommandation with easy-peasy.

After checking the code of connected-react-router, it seem that the only missing thing to work with is the context reference.

I don't understand why you mention connected-react-router in the documentation https://github.com/ctrlplusb/easy-peasy#reducerfn and why it's said:

... integrations with existing libraries, or legacy Redux code ...

And after there is an example that use connect decorator from react-redux, meaning for me that it's fully compatible. https://github.com/ctrlplusb/easy-peasy#finally-use-connect-against-your-components

Why not simply replace the easy-peasy context by react-redux 6 context using
import { ReactReduxContext as StoreContext } from 'react-redux'

Reopening for more discussion and clarity. Will respond soon. 馃憤

Maybe it is not a problem to provide two contexts, one from react-redux:

import { Provider } from 'react-redux'
import { StoreProvider } from 'easy-peasy';
export default hot(() => <StoreProvider store={store} ><Provider store={store} >
    <ConnectedRouter history={history}> { /* place ConnectedRouter under Provider */ }
      { /* your usual react-router v4 routing */ }
    </ConnectedRouter>
  </Provider></StoreProvider>)

where both referencing same store.

@strobox - completely correct 馃憤

This is the approach I adopt for interop, but I prefer to look for alternative libraries where I don't need to have react-redux as a dependency. Not always possible though, in which case your "workaround" does help.

This issue surfaces issues with the documentation though, which I wish to address. I'll reply soon.

Hey @takion

Thanks again for raising this issue. It definitely surfaces issues with the current documentation. Specifically in terms of integrating with the existing react-redux system.

I apologise for any confusion.

I have been trying to keep react-redux out of this library as technically it is not a requirement to it working, but I will update the documentation to be more explicit about this decision. I will also provide @strobox's example as how this isn't a limitation as you can simply install and expose react-redux's context yourself.

Hey @ctrlplusb,

Thanks to you for taking it in account.
I'm actually working on my own implementation inspired by redux-react-hook, and the great api of easy-peasy at
https://github.com/takion/redux-up-hook
and https://github.com/takion/redux-up-context (based on rematch)
And now I understand why you make your own context, but I found that make it optionalisable is a good workaround for many problems.

Was this page helpful?
0 / 5 - 0 ratings