Reading-Notes

Reading Notes

React Docs - Thinking in React

What is the single responsibility principle and how does it apply to components?

A component should only do one thing, if it gets bigger it shoulld broken down into smaller subcomponents.

What does it mean to build a ‘static’ version of your application?

To build a static version of an application basically means to build a version that takes the data model and renders a UI but has no interactivity. In a static version it is important to use props and not state. This is helpful to flush out all the components and see how the application will be laid out and function without user interaction that may create problems.

Once you have a static application, what do you need to add?

props?

What are the three questions you can ask to determine if something is state?

If the answer is yes to these, they are probably not state.

How can you identify where 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.

https://reactjs.org/docs/thinking-in-react.html

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. https://eloquentjavascript.net/05_higher_order.html#h_xxCc98lOBK

Explore the greaterThan function as defined in the reading. In your own words, what is line 2 of this function doing?

Line two is an arrow function within the greaterThan function, it returns the value ‘m’ when it is greater than ‘n.’

Explain how either map or reduce operates, with regards to higher-order functions.

Both map and reduce can be included within another function in order to manipulate an array.