![alt screenshot](http://i.imgur.com/1i4bKcZ.jpg =200x)
This Git
As i learn i jot down some notes here for a quick reference in future.
Probably some wrong info here.
This Git shows a simple example of a redux app
Flow
- Create your normal React components as you normally would
- Create a smart component (ie, container), in our case, <App /gt;
- Create your reducer and actions
- Create a store with store = createStore(reducer)
- Wrap your smart component(s) in <Provider store={store} />
- ie, <Provider store={store}><App /></Provider>
- Smart components render dumb components, passing props to them.
Dumb components are not aware of state, only the props passed to them - These props can be any data, or functions you want to trigger an action with.
For example, you have this structure
| - App clickButton={fn}(smart component)
| ---- Chatlog clickButton={fn}(dumb component)
| -------- Form onClick={this.props.clickButton()}(dumb component)
In our case, the function being passed down to from App to Form is translated to this:
function (text) { return dispatch(sendMessage(text))}
, which is, in turn,
function (text) { return dispatch({type:SEND_MESSAGE, message: text})}
and the reducer will react. - connect(selector)(App) where selector is a selector function and App is the smart component
A good table to keep in mind:
+----------------------------------------------------------------------------+
| | Smart components | Dumb components |
+------------------+---------------------------+-----------------------------+
| Location | Top Level, route handlers | Middle & leaf components |
+------------------+---------------------------+-----------------------------+
| Aware of redux | Yes | No |
+------------------+---------------------------+-----------------------------+
| To read data | Subscribe to redux state | Read data from props |
+------------------+---------------------------+-----------------------------+
| To change data | Dispatch refux actions | Invoke callbacks from props |
+------------------+---------------------------+-----------------------------+