reading-notes

Class 301.05

Notes

Readings

React Docs - Thinking in React

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

    A component should be responsible for one thing

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

    Build something without any interactivity. Build a website takes lots of typing, no thinking; whereas interactivity requires lots of thinking and little typing

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

    we must find the minimal but complete representation of UI state

  4. What are the three questions you can ask to determine if something is state?
    1. Does it remain unchanged over time? If so, it isn’t state.
    2. Is it passed in from a parent via props? If so, it isn’t state.
    3. Can you compute it based on existing state or props in your component? If so, it definitely isn’t state!
  5. 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 their closest common parent component—a component above them all in the hierarchy.
    • Decide where the state should live:
    • Often, you can put the state directly into their common parent.
    • You can also put the state into some component above their common parent.
    • 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 parent component.

Higher-Order Functions

  1. 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

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

    it returns a function that takes a single input (m) and it returns true if m > n, otherwise it returns false

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

    map calls a function on each element, returning a new array. reduce repeatedly applies a function to accumulate a single value. Both utilize passed in functions to shape their operation.

Things I want to learn more about

References