From the course: Type-Safe Redux: Advanced Techniques with TypeScript

Unlock the full course today

Join today to access over 24,900 courses taught by industry experts.

Creating custom hooks for Redux logic

Creating custom hooks for Redux logic

- [Instructor] So far we've explored how to connect Redux to react using useSelector and useDispatch, which has been great for assessing and updating state in our components. But now we are going to take things a bit further by encapsulating that logic into custom hooks. This will make our components not only cleaner, but also reusable and efficient. Custom hooks allow us to take the repetitive parts of our code, package them neatly into reusable functions, and then use them whenever needed. So instead of duplicating the same useSelector and useDispatch logic across multiple components, we can abstract this into a custom hook. This not only makes our components more readable and reasonable, but also helps us to avoid the common problem of passing down unnecessary nested props from parent to child components. With custom hooks, both parents and child components, as well as others throughout the app can directly assess and feed from one central source, making the code cleaner and…

Contents