Course lesson
Replacing mapStateToProps with the useSelector Hook
Redux provides a useSelector hook for easy access to state within a function component. This hook replaces the mapStateToProps function which was used previously with connect(). The hooks API is a lot simpler and can be combined nicely with selector functions.
- Duration
- 1 min
- Access
- Free
- Transcript
- Available
Redux provides a useSelector hook for easy access to state within a function component. This hook replaces the mapStateToProps function which was used previously with connect(). The hooks API is a lot simpler and can be combined nicely with selector functions.
The basic API looks like this:
const value = useSelector(state => state.reducerName.value)When used with a selector function it looks like this:
const value = useSelector(getValue)