-
Summarize the five steps of thinking in react.
- The five steps of thinking in React are:
- Break the UI into a component hierarchy
- Draw boxes around every component (and subcomponent) in the mock and give them all names.
- Build a static version in React
- Build a version of the UI that takes the data model and renders the UI but has no interactivity.
- Identify the minimal (but complete) representation of UI state
- Identify the minimal set of mutable state that the UI needs.
- Identify where your state should live
- Identify which component each piece of state should live in.
- Add inverse data flow
- Add inverse data flow to make the UI interactive.
- Break the UI into a component hierarchy
- The five steps of thinking in React are:
-
What is one reason a local variable isn’t sufficient for managing a React component?
- Local variables are not sufficient for managing a React component because they are not preserved between renders. They are reinitialized each time the component is rendered. This means that they cannot be used to store state.
-
What is the argument to the useState hook, and what are the two parts of its return array?
- The argument to the useState hook is the initial state. The two parts of its return array are the current state and a function that updates the state. The function that updates the state can be called with a new state value, which will cause the component to re-render with the new state value. The function that updates the state can also be called with a function that takes the current state as an argument and returns a new state value. This is useful when the new state value depends on the current state value.
-
How can Component A access state from Component B?
- Component A can access state from Component B by passing the state from Component B to Component A as a prop. Component A can then access the state from Component B by accessing the prop. If Component B needs to update the state, it can pass a function to Component A as a prop. Component A can then call the function with the new state value, which will cause Component B to re-render with the new state value. If Component B needs to update the state based on the current state value, it can pass a function to Component A as a prop. Component A can then call the function with a function that takes the current state as an argument and returns a new state value. This is useful when the new state value depends on the current state value.
-
What are your learning goals after reading and reviewing the class README?
- Goal 1: I want to understand how to use React to build a UI. After gaining a decent foundation with React, I would like to update the UI in past projects that I have built.
- Hooks in general.
