redux-store
The Goal
Create a store using
react-redux
to manage everythingPut it in
index.js
Wrap it in a
Provider
element fromreact-redux
createStore
creates a Redux storeWe still need to provide specific actions and dispatchers
Provider
is a way to create the equivalent of a global variableAdds named data to the props of all of the elements within its scope
We won't actually refer to
store
ourselvesIt will be connected when we wire everything together
Connecting the Pieces
Modify
App.js
(our container)connect
takes two functionsWraps the
App
class with something that knows how to talk to a default storeThis code relies on the
store
variable created by theProvider
Mapping State to Properties
Given a state, generate the change to the properties
Mapping Dispatch Function to Properties
Constructor
Initialize state as usual
Initial Data Fetch
As before
Rendering
Looks pretty much the same as well
Which is the point
Get
onSearchChange
from the propertiesThis is the function named in the object returned by
mapDispatchToProps
react-redux
wires all of this up for us
Last updated
Was this helpful?