React Flashcards
Do states persist when a component is re rendered?
Yes
What does it mean to “lift a state”?
Move a state to a parent component
When would it be practical to lift a state?
When a sibling component also needs access to that state.
Can props be passed from parent to child?
Yes
Can props be passed from child to parent?
No
Can props be passed from sibling to sibling?
No
How would you remove an item from an array stored in a state?
Use the filter function to create a new array that excludes the item
setItems((items) => items.filter(item => item.id !== id))
What is a controlled element?
An element that has it’s value defined by a state and also has an event handler which sets the state on change.
When would you need to use back ticks instead of quotations?
When you need to concat a variable and a string inside JSX {}
eg. <li className={pizza ${pizzaObject.soldOut ? "sold-out" : ""}
}>
What is a derived state?
A normal variable that is using data from a state to calculate new data.
What is a children prop?
Children prop is the html content in between the opening and closing tag of a component. The component will receive this html as a prop called “children”.
What is a Structural component?
A component that contains other components and its purpose is to be the parent.
Examples would be pages, layouts, screens.
They can be large non reusable components but they don’t have to be.
What is a Stateless / Presentational component?
A component that has no state. It might receive and display props. It is usually small and reusable.
What is a Stateful component?
A component that has a state. Can be small and reusable.
What is prop drilling?
Passing a prop down to a component that is deeply nested. This means multiple components that don’t use the prop will need to receive it so they can pass it on to a child component until it reaches the component that will actually use the prop.