facebookarchive / redux-react-hook

React Hook for accessing state and dispatch from a Redux store
MIT License
2.16k stars 103 forks source link

Seamless gradual upgrade from react-redux #47

Closed langpavel closed 5 years ago

langpavel commented 5 years ago

Related to #3

Edit: This will not work because react-redux injects state but redux-react-hooks injects store into Context

If redux is same, then reusing context should be as easy as injecting foreign context object:

https://github.com/facebookincubator/redux-react-hook/blob/3a86bc02ca81def12e0240c986d56ee1da5fc792/src/create.ts#L21-L30

new code (will not work) ```ts export function create< TState, TAction extends Action, TStore extends Store >(customContext?: React.ContextType): { StoreContext: React.Context; useMappedState: (mapState: (state: TState) => TResult) => TResult; useDispatch: () => Dispatch; } { const StoreContext = customContext || createContext(null); // ... } ```

This may break if context shapes from react-redux and redux-react-hook are different — they are different

ianobermiller commented 5 years ago

In our app we made a StoreContext.react.js component that applies both the react-redux provider and the redux-react-hook provider, and just use that everywhere. As you pointed out, the shapes are not the same, so this won't really work.