It's ideal to contain state in one component at the root of your application. That way you can always keep track of where state lives and update it in a maintainable way.
- [Instructor] When working with a React application,…it's a good rule of thumb to keep state…in the root of the tree.…In other words, your root component,…in this case, the library component,…should hold all of the state variables…and pass down that information to the children.…You can read more about the idea of lifting state up…or having state at the root…in the React documentation.…So, the reason for this…is if I have local state in all of my components,…it's really easy to lose track of that state,…and for some of these variables to be incorrect.…
Sometimes the state at the root is called…the source of truth,…and you want that source of truth…to always be in the same place…where you know where to find it.…So, we're going to add another state variable…here to the library,…and the state variable that we're going to use…is called freeBookmark.…Now, freeBookmark is going to be set to true.…Let's also change our open variable to true as well.…Now, the freeBookmark state variable,…we want to pass this down to the child of the library,…
- Refactoring elements with JSX
- Creating components
- Adding component properties and methods
- Displaying child components
- Working with props and state
- Conditional rendering
Skill Level Intermediate
1. What Is React?
2. Introduction to React Elements
3. React Components
4. Props and State
5. Additional Library Features
- 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.