Why use Redux?
- Redux helps us to avoid the problem of prop drilling!
- Instead of asking data to parent components, you can directly get that from the store.
- Create Big apps with Redux if your app shares a lot of data between components you should use Redux.
- Store, Reducers, Actions, Constants
- Data can be separated using `Multiple reducers` & will be stored in a single Store.
- in Index.js import Provider & Store. And then Wrap <App /> component with Provider.
Redux Devtools Extension.
- To view states in our dev tools. you can see state movements.
- you have to add/connect your app redux dev tools extension.
- const store = createStore(rootReducer, composeWithDevTools());
Add to Cart Example:
- What is Action: Send data from React to Store. if you click on the `Add to cart` button data will be shown to the cart.
- Reducer: Gets data from action & pushes data to store. check for the action & push data accordingly!
- container:
- Connect React with Redux: (mapStateToProps & mapDispatchToProps)
- Shopping Types
- Shopping Actions
- Shopping Reducers
- Get to know about Connect function in Redux.
Amazed:
- By just adding `+` before `action.payload.qty` type `string` value has been converted to type `number`
console.log("action.payload.qty ===> ", action.payload, " type ===>",
typeof +action.payload.qty)
0 comments:
Post a Comment