Thinking In React
- What is the single responsibility principle and how does it apply to components?
-A component should only really do one thing, if it changes it should decompose into smaller sub components
- What does it mean to build a ‘static’ version of your application?
- It is something that renders the UI but doesn’t do anything. It is more typing than thinking.
- Once you have a static application, what do you need to add?
- You need to add all your components and use them. Also, pass data using props.
- What are the three questions you can ask to determine if something is state?
- Is it passed in from a parent via props? If so, it probably isn’t state.
- Does it remain unchanged over time? If so, it probably isn’t state.
- Can you compute it based on any other state or props in your component? If so, it isn’t state.
- How can you identify where the state needs to live?
- Identify every component that renders something based on that state.
- Find a common owner component (a single component above all the components that need the state in the hierarchy).
- Either the common owner or another component higher up in the hierarchy should own the state.
- If you can’t find a component where it makes sense to own the state, create a new component solely for holding the state and add it somewhere in the hierarchy above the common owner component.
Higher order functions
- What is a “higher-order function”?
- Functions that use other function that either return them or renders them
- Explore the greaterThan function as defined in the reading. In your own words, what is line 2 of this function doing?
- It is a function that is seeing if M is greater than n and will return the answer
- Explain how either map or reduce operates, with regards to higher-order functions.
- It is a function that uses other functions inside to return something.