From the course: React: State Management

Unlock this course with a free trial

Join today to access over 25,300 courses taught by industry experts.

Solution: Subscribing to state changes

Solution: Subscribing to state changes - React.js Tutorial

From the course: React: State Management

Solution: Subscribing to state changes

(upbeat music) - [Instructor] Now let's see the solution to the exercise. We're going to do a lot of refactoring, and here, the purpose is to move things into their own components. We want to allow every component to subscribe to state changes independently instead of passing data by using the props. And same for any feature that we are passing, like for the function that we pass as props. This needs to be handled actually directly from the components in order to respect also the principle of single responsibility. So anything related to the form should be inside the form components. So I'm going to take from line here all the way to line 49. I'm going to cut and put it inside the form right here, and I'm going to take also here, because you see that this is no longer used. I'm going to take this and add it to the form, actually the ref as well, because we're going to use the ref to access one node in the form, and I'm…

Contents