From the course: React: Lifecycles
Unlock this course with a free trial
Join today to access over 22,500 courses taught by industry experts.
Initial state - React.js Tutorial
From the course: React: Lifecycles
Initial state
- [Instructor] In the last video, we talked about setting our initial props or giving default props to our component. In this video, we're going to talk about giving our component an initial state. Now, I want to draw attention to the fact that there used to be a react method that called initial state and would actually set your component's initial state. But, the way that the react API works right now is we actually have simpler ways of setting the initial state and that that old method has been depreciated. So, let's look at the two different ways we can give our component an initial state. Now, setting the initial state of your component is not a static method like display name or default props. That actually makes it even more simple to set it, so you can just say state equals make an object and then pass in your values, so we could say ourInitialState is golden, all right. It doesn't really matter what we put in here. We're just testing out our initial state. So, you can just say…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.