From the course: React: Advanced Code Challenges
Unlock this course with a free trial
Join today to access over 25,200 courses taught by industry experts.
Separating logic with the hooks pattern - React.js Tutorial
From the course: React: Advanced Code Challenges
Separating logic with the hooks pattern
- [Instructor] Separating logic and state management from presentation is a powerful pattern in React that allows to improve performance, reusability, and testability. A clean way to achieve this is by using custom hooks. So let's see how to create custom hooks. So, that's going to allow to isolate the logic. And first, what we've done is to already split the usage of the context objects. So we have two separate context objects to handle differently and individually state managements. So we handle the state for the dashboard only and separately also whatever is related to the ToolBarContext. All right. And we're going to be able to see that now, so let's actually open the console. We're going to see that even though, here I'm going to open the profiler. So now we only update the dashboard, and if I add one thing, it's going to be done separately. It's not going to trigger actually any re-render and update for the dashboard, it's going to be handled differently and separately. So…