Course lesson
Applying the useSelector and useDispatch Redux Hooks to Additional Components
In this lesson we quickly migrate our <RateTable> and <CurrencyCodePicker> to the Redux Hooks API. Nothing new is covered here that isn't covered in our previous lessons, but I am hoping it will be useful to practice this technique and also to see how rapidly...
- Duration
- 2 min
- Access
- Free
- Transcript
- Available
In this lesson we quickly migrate our <RateTable> and <CurrencyCodePicker> to the Redux Hooks API. Nothing new is covered here that isn't covered in our previous lessons, but I am hoping it will be useful to practice this technique and also to see how rapidly we can convert these components to the new syntax.
What's stopping you from using these techniques in your own app!?
import useSelectoranduseDispatch- Copy the body of
mapStateToPropsto the top of your component and convert each line to its own variable, pulled in withuseSelectorhook - If needed, create a
dispatchfunction withuseDispatch() - Replace any dispatched actions with either a direct call to
dispatchor create a function with the same name as the variable. - Remove any now un-needed props
- Delete propTypes,
mapStateToPropsand themapDispatchToPropsfunction - You can also remove
connect()but we saved that for another lesson :D