Redux React Hooks
Redux React Hooks is an experimental library using an experimental version of react (16.7.0-alpha.0).
https://reactjs.org/docs/hooks-intro.html
Why?
To learn, have fun, and provide a solution to a problem that will help other developers.
I won't be able to do this alone, all feedback is helpful!
Current todos and goals
There is still a lot to be done.
- Implement better testing
- Understand the implications of certain patterns
- Work to prove a smooth developing and testing experience
Getting Started
1.) First you will have to install redux-react-hooks, to install all you have to do is run:
npm i redux-react-hooks
To implement, you must be using React >=16.7.0-alpha.0, and redux.
2.) To start using redux-react-hooks, you will still have to wrap the components you want to have access to your store within a "ReduxProvider"
/* Import Redux Provider */;; /* create your store */const store = ; { return /* pass your store to the provider and wrap your component with ReduxProvider */ <ReduxProvider store=store> <SomeComponent /> </ReduxProvider> );
3.) Finally, you can begin using your redux react hooks within your components:
/* Import Redux React hooks */;; { /* Allows us to access our state */ const users = ; /* binds our actions */ const actions = ; actions; ...}
Testing
Before hooks, testing connected components was a pain.
1.) To test a component using redux-react-hooks, you must create a mock store.
Make sure your NODE_ENV=test
/* import mockReduxStore */;; ;
In our first example we wrapped in a ReduxProvider, we wont have to do that when testing.