Understand the state of

What is a state?

Baidu encyclopedia

The condition of a physical system.

The characteristic of a state is that it can change. What doesn’t change is the property, what changes is the state.

Example: useState,

const [target, setTarget] = useState(0); // Targer is a state, setTarget is a behavior, and useState(0) is a hook APICopy the code

The React in the UI,

    UI = data => {
        return <div></div>
    }
Copy the code

role

Understanding: depend on the role of XXX change

Context

The background, the circumstances, the context, the facts that should be known.

These concepts are very important, and understanding them will help you get started with hook.

  1. One hook for each behavior
  2. Don’t use one big state, different types of states are different hooks
  3. Stop thinking about the life cycle
  4. React.memo() reduces redrawing times
  5. Hoook synchronization problem
  6. Construct hook encapsulation behavior.

useEffect

The resources

  • React Hook B
  • Can I use async/await with useEffect?
  • React Hooks Tutorial