Concepts Flashcards
prop drilling
AKA threading, sending props from top way down to great-grandchildren to give access-you can use Context to solve it
components
- let you split the UI into independent, reusable pieces, and think about each piece in isolation.
- can be defined as either classes or functions
props
read-only
state
can be controlled and manipulated by the component
ex. setState used to modify the state in an API call or something similar
render
-only method required in a class component
-when called will examine this.props and/or this.state
-returns- something- like an element
This will happen at least once
If the components props change, render can happen again
If the components state changes, the render can also happen again
update state?
use the method this.setState, which passes an object “merge” over the top of the existing state
Which lifecycle method is best suited for AJAX calls?
componentDidMount- this method executes once after the render method is executed the first time- user sees the page and placeholder data while componentDidMount executes and so you can use setState to update component once date is received
binding problem with event handlers
in JS class methods, like the ones used for event handlers, are not bound by default, so taking extra steps to bind event handlers is important.
solutions to binding problem with methods
- Use .bind to bind event handler in the class constructor
- Use arrow function in JSX (do this in render, rather than class constructor
- Change event handler to arrow function class method(similar to the previous method, but in event handler, instead of JSX)
Context
- provides a way to share values like these between components without having to explicitly pass a prop through every level of the tree
- designed to share data that is considered ‘global’