Read Class 05
Reading
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
- What does it mean to build a ‘static’ version of your application?
- a build version of the UT for m the data model without adding any interactivity
- Once you have a static application, what do you need to add?
- What are the three questions you can ask to determine if something is state?
- Does it remain unchanged over time?
- Is it passed in from a parent via props?
- Can you compute it based on existing state or props in your component?
- How can you identify where state needs to live?
- identify components that render something based on that state
- find their closest common parent component
- this would be the component above them all in the hierarchy
- can’t seem to find the component that makes sense to hold the state?
- make a new component strictly for that state above the common parent component!
Higher-Order Functions
- What is a “higher-order function”?
- functinos that operate on other functions, either by taking them as arguments or by returning them
- Explore the
greatThan
function as defined in the reading. In your own words, what is line 2 of this function doing?
- line 2 is returning the outcome of m > n comparison
- Explain how either
map
or reduce
operates, with regards to higher-order functions.
map
transforms an array by applying a function to all of its elements and building a new array from the returned values. The new array will have the same length as the input array while the new content has been “mapped” to a new form by the function
reduce
builds a value by repeatedly taking a single element from the array and combining it with the current value