user-profile-img

JoJo

@loveboobs• Mar 16, 2023open-state

实拍望京:韩国人撤了,互联网新贵和明星们来了,北京朝阳区最奢华的商务区之一(小叔TV EP243) - YouTube

snapshot

3:30

snapshot

3:36

snapshot

3:47

-

实拍望京:韩国人撤了,互联网新贵和明星们来了,北京朝阳区最奢华的商务区之一(小叔TV EP243) - YouTubewww.youtube.com

user-profile-img

JoJo

@loveboobs• Mar 9, 2023open-state

Extracting State Logic into a Reducer • React

Components with many state updates spread across many event handlers can get overwhelming. For these cases, you can consolidate all the state update logic outside your component in a single function, called a reducer.

Each of its event handlers calls setTasks in order to update the state. As this component grows, so does the amount of state logic sprinkled throughout it.

To reduce this complexity and keep all your logic in one easy-to-access place, you can move that state logic into a single function outside your component, called a “reducer”. Reducers are a different way to handle state. You can migrate from useState to useReducer in three steps: Move from setting state to dispatching actions. Write a reducer function. Use the reducer from your component.

-

Extracting State Logic into a Reducer • Reactbeta.reactjs.org

user-profile-img

JoJo

@loveboobs• Mar 7, 2023open-state

Preserving and Resetting State

Notice how the moment you stop rendering the second counter, its state disappears completely. That’s because when React removes a component, it destroys its state.

annotationreact停止渲染这个组件这个组件的状态也就消失了, 很合理的操作,相当于树上没了那个节点,重新加上当然是useState(0),毕竟这个状态是在子组件内定义的

Same component at the same position preserves state

annotation位置一样,key一样,根据diff算法就会保留state 以下这个例子疑问多多

pass it down to them via props. This is known as lifting state up, and it’s one of the most common things you will do writing React code.

-

Preserving and Resetting State • Reactbeta.reactjs.org

user-profile-img

JoJo

@loveboobs• Mar 4, 2023open-state

Passing Data Deeply with Context • React

Usually, you will pass information from a parent component to a child component via props. But passing props can become verbose and inconvenient if you have to pass them through many components in the middle, or if many components in your app need the same information. Context lets the parent component make some information available to any component in the tree below it—no matter how deep—without passing it explicitly through props.

This example uses heading levels because they show visually how nested components can override context. But context is useful for many other use cases too. You can use it to pass down any information needed by the entire subtree: the current color theme, the currently logged in user, and so on.

This tells React: “if any component inside this <Section> asks for LevelContext, give them this level.” The component will use the value of the nearest <LevelContext.Provider> in the UI tree above it.

-

Passing Data Deeply with Context • Reactbeta.reactjs.org

user-profile-img

JoJo

@loveboobs• Feb 28, 2023open-state

Reacting to Input with State

Step 1: Identify your component’s different visual states

Step 2: Determine what triggers those state changes

Step 3: Represent the state in memory with useState

-

Reacting to Input with State • Reactbeta.reactjs.org

user-profile-img

JoJo

@loveboobs• Feb 25, 2023open-state

JavaScript this

this is not unique to JavaScript. In other languages however, this always point sat instance of a class. On the other hand, in JavaScript, this is determined as execution context is created

-

JavaScript thisgo-kahlo-lee.ghost.io

user-profile-img

JoJo

@loveboobs• Feb 25, 2023open-state

Execution Context

As JavaScript engine starts executing main.js file from top to bottom, it first creates execution context for JavaScript file itself, namely for the entire program, which is called 'global execution context.' Then, every time a function is called, new environment context is created and put at the top of call stack.

-

Execution Contextgo-kahlo-lee.ghost.io

user-profile-img

JoJo

@loveboobs• Feb 24, 2023open-state

Sharing State Between Components

pass it down to them via props. This is known as lifting state up, and it’s one of the most common things you will do writing React code.

Notice how pressing one panel’s button does not affect the other panel—they are independent.

annotation这里相当于组件内的函数在两个组件内被两个组件分别调用了,是完全不相干的,假如他这会相关,那组件的state管理也就失去了价值

In contrast, you might say a component is “controlled” when the important information in it is driven by props rather than its own local state. This lets the parent component fully specify its behavior. The final Panel component with the isActive prop is controlled by the Accordion component.

annotation状态的受控与否,取决于他们在哪里定义的,不受上级指示的状态可能在底层级别接受着用户最低级的交互,这和社会是一样的
-

Sharing State Between Components • Reactbeta.reactjs.org

user-profile-img

JoJo

@loveboobs• Feb 23, 2023open-state

Self-Driving Tesla vs Sunday Traffic to Supercharger | FSD Beta 10.69.25.2 - YouTube

snapshot

6:00

-

Self-Driving Tesla vs Sunday Traffic to Supercharger | FSD Beta 10.69.25.2 - YouTubewww.youtube.com

user-profile-img

JoJo

@loveboobs• Feb 22, 2023open-state

Passing Props to a Component

Sometimes, passing props gets very repetitive:

-

Passing Props to a Component • Reactbeta.reactjs.org