You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Additionally, starting in React 18, the function passed to `useEffect`will fire synchronously **before**layout and paint when it's the result of a discrete user input such as a click, or when it's the result of an update wrapped in [`flushSync`](/docs/react-dom.html#flushsync). This behavior allows the result of the effect to be observed by the event system, or by the caller of [`flushSync`](/docs/react-dom.html#flushsync).
> This only affects the timing of when the function passed to `useEffect`is called - updates scheduled inside these effects are still deferred. This is different than [`useLayoutEffect`](#uselayouteffect), which fires the function and processes the updates inside of it immediately.
151
+
> 這只會影響傳遞給 `useEffect`的 function 的被呼叫時間 - 在這些 effect 中安排的更新仍然會被延遲。這與 [`useLayoutEffect`](#uselayouteffect) 不同,後者會觸發 function 並立即處理其更新。
@@ -527,12 +527,12 @@ useDebugValue(date, date => date.toDateString());
527
527
constdeferredValue=useDeferredValue(value);
528
528
```
529
529
530
-
`useDeferredValue`accepts a value and returns a new copy of the value that will defer to more urgent updates. If the current render is the result of an urgent update, like user input, React will return the previous value and then render the new value after the urgent render has completed.
This hook is similar to user-space hooks which use debouncing or throttling to defer updates. The benefits to using `useDeferredValue`is that React will work on the update as soon as other work finishes (instead of waiting for an arbitrary amount of time), and like [`startTransition`](/docs/react-api.html#starttransition), deferred values can suspend without triggering an unexpected fallback for existing content.
#### Memoizing deferred children {#memoizing-deferred-children}
535
-
`useDeferredValue`only defers the value that you pass to it. If you want to prevent a child component from re-rendering during an urgent update, you must also memoize that component with [`React.memo`](/docs/react-api.html#reactmemo)or[`React.useMemo`](/docs/hooks-reference.html#usememo):
534
+
#### Memoizing 延遲的 Children {#memoizing-deferred-children}
Memoizing the children tells React that it only needs to re-render them when `deferredQuery`changes and not when `query`changes. This caveat is not unique to `useDeferredValue`, and it's the same pattern you would use with similar hooks that use debouncing or throttling.
`startTransition` lets you mark updates in the provided callback as transitions:
571
-
571
+
讓你在提供的 callback 中標記更新為 transitions:
572
572
```js
573
573
startTransition(() => {
574
574
setCount(count +1);
575
575
})
576
576
```
577
577
578
-
`isPending`indicates when a transition is active to show a pending state:
578
+
`isPending`表示當一個 transition 是 active 時顯示 pending state:
579
579
580
580
```js
581
581
functionApp() {
@@ -597,7 +597,7 @@ function App() {
597
597
}
598
598
```
599
599
600
-
> Note:
600
+
> 注意:
601
601
>
602
602
> Updates in a transition yield to more urgent updates such as clicks.
603
603
>
@@ -645,7 +645,7 @@ function NameFields() {
645
645
}
646
646
```
647
647
648
-
> Note:
648
+
> 注意:
649
649
>
650
650
> `useId` generates a string that includes the `:` token. This helps ensure that the token is unique, but is not supported in CSS selectors or APIs like `querySelectorAll`.
> `getSnapshot` must return a cached value. If getSnapshot is called multiple times in a row, it must return the same exact value unless there was a store update in between.
The signature is identical to `useEffect`, but it fires synchronously _before_ all DOM mutations. Use this to inject styles into the DOM before reading layout in [`useLayoutEffect`](#uselayouteffect). Since this hook is limited in scope, this hook does not have access to refs and cannot schedule updates.
711
711
712
-
> Note:
712
+
> 注意:
713
713
>
714
714
> `useInsertionEffect` should be limited to css-in-js library authors. Prefer [`useEffect`](#useeffect) or [`useLayoutEffect`](#uselayouteffect) instead.
0 commit comments