React Docs - Thinking in React
What is the single responsibility principle and how does it apply to components? A component should ideally only do one thing. If it ends up growing, it should be decomposed into smaller subcomponents.
What does it mean to build a ‘static’ version of your application? A static version of an application displays content without having any interactivity or functionality.
Once you have a static application, what do you need to add? Think of the minimal set of mutable state that the app requires.
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 state needs to live? For each piece of state in your application:
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 operate on other functions, either by taking them as arguments or by returning them, are called higher-order functions.
Explore the greaterThan function as defined in the reading. In your own words, what is line 2 of this function doing?
m is a variable that represents a value higher than the number passed in the greaterThan function. It is used to create a function that can act as a test where one can tell if a number passed into it is greater than 10.
Explain how either map or reduce operates, with regards to higher-order functions. Array.map takes a function as its argument. That function is then applied to every element within the array. In addition to the utility of this function, the fact thsat it takes other functions as an argument means that it can more easily be combined with other functions.