Understand the application of initial state vs. defaultProps.
- [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 state equals…and this will set on your component.…
Carl Peaslee helps you build a number of small reusable components that will be useful in future projects. Along the way, he discusses the syntax and uses of lifecycle methods, how state affects React lifecycles and your apps, and how to set static display name, default props, and initial state. Plus, learn how to gather performance data and improve performance by minimizing component updates.
- Overview of React lifecycles
- Initial state
- Default props
- Mounting: componentWillMount, componentDidMount, and render
- Updating: shouldComponentUpdate, componentWillUpdate, and componentDidUpdate
- Controlling component updates
- Using react-addons-perf to get performance data
Skill Level Intermediate
React.js: Building an Interface (2016)with Ray Villalobos1h 21m Intermediate
1. Overview of Lifecycles
2. Defaults, Initialization, and Construction
5. Optimizing Components
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.