A proof-of-concept app demonstrating how one can implement Redux with React Hooks and the context API
A proof-of-concept app demonstrating how one can implement Redux with React Hooks and the context API.
The app is a straightforward React app that renders user-submitted messages, as well as displaying quotes from the Ron Swanson Quotes API.
Given the small size of the codebase, the app's source directory src
houses four directories:
actions
- the action types and action creators dispatched by the appcomponents
- the presentational and connected components, both of which are typically specified together in each modulereducers
- contains a sole reducer for computing the next state for a given actionstate
- type definitions and defaults for our shared stateThe bindings module (bindings.tsx
) effectively reimplements React Redux (react-redux
), with implementations of:
Provider
component
connect
function
For simplicity's sake, our implementation takes a few liberties:
State
typeProvider
doesn't accept a store prop, instead taking a reducer function directlyconnect
's mergeProps
parameter is not implementedcombineReducers
and React Redux's connectAdvanced
are missingTo set up:
git clone https://github.com/jamesseanwright/roll-your-own-redux.git
cd react-observable-state
npm i
Then you can run one of the following commands:
npm run dev
- builds the project with rollup.js and serves it from port 8080npm test
- runs the unit tests (append -- --watch
to launch Jest's watch mode)