Skip to content

Commit 0764f5f

Browse files
theheliumawxiaoxian2020fwqaaqYucohnyXleine
authored
docs(cn): translate reference/react/index into Chinese (#1098)
Co-authored-by: Xavi Lee <[email protected]> Co-authored-by: fw_qaq <[email protected]> Co-authored-by: Yucohny <[email protected]> Co-authored-by: Xleine <[email protected]>
1 parent 2c21681 commit 0764f5f

File tree

1 file changed

+37
-37
lines changed

1 file changed

+37
-37
lines changed

src/content/reference/react/index.md

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
---
2-
title: "Built-in React Hooks"
2+
title: "内置 React Hook"
33
---
44

55
<Intro>
66

7-
*Hooks* let you use different React features from your components. You can either use the built-in Hooks or combine them to build your own. This page lists all built-in Hooks in React.
7+
**Hook** 让你可以在组件中使用不同的 React 功能。你可以使用内置的 Hook 或者把它们组合起来建立你自己的。本页列出了 React 中所有的内置 Hook。
88

99
</Intro>
1010

1111
---
1212

13-
## State Hooks {/*state-hooks*/}
13+
## 状态 Hook {/*state-hooks*/}
1414

15-
*State* lets a component ["remember" information like user input.](/learn/state-a-components-memory) For example, a form component can use state to store the input value, while an image gallery component can use state to store the selected image index.
15+
**state** 让一个组件 [“记住”用户输入的信息](/learn/state-a-components-memory),比如,一个表单组件可以使用 state 来存储输入值,而一个图片库组件可以使用 state 来存储选定的图片索引。
1616

17-
To add state to a component, use one of these Hooks:
17+
要给一个组件添加状态,可以使用下面的 Hook:
1818

19-
* [`useState`](/reference/react/useState) declares a state variable that you can update directly.
20-
* [`useReducer`](/reference/react/useReducer) declares a state variable with the update logic inside a [reducer function.](/learn/extracting-state-logic-into-a-reducer)
19+
* [`useState`](/reference/react/useState) 声明了一个你可以直接更新的 state 变量。
20+
* [`useReducer`](/reference/react/useReducer) 声明了一个带有更新逻辑的 state 变量在一个 [reducer 函数](/learn/extracting-state-logic-into-a-reducer) 中。
2121

2222
```js
2323
function ImageGallery() {
@@ -27,11 +27,11 @@ function ImageGallery() {
2727
2828
---
2929
30-
## Context Hooks {/*context-hooks*/}
30+
## Context Hook {/*context-hooks*/}
3131
32-
*Context* lets a component [receive information from distant parents without passing it as props.](/learn/passing-props-to-a-component) For example, your app's top-level component can pass the current UI theme to all components below, no matter how deep.
32+
*context* 让一个组件 [从远处的父组件接收信息,而不需要将其作为 props 传递](/learn/passing-props-to-a-component)。比如,app 的顶层组件可以将当前的 UI 主题传递给下面的所有组件,无论它们层级多深。
3333
34-
* [`useContext`](/reference/react/useContext) reads and subscribes to a context.
34+
* [`useContext`](/reference/react/useContext) 读取并订阅一个 context
3535
3636
```js
3737
function Button() {
@@ -41,12 +41,12 @@ function Button() {
4141
4242
---
4343
44-
## Ref Hooks {/*ref-hooks*/}
44+
## Ref Hook {/*ref-hooks*/}
4545
46-
*Refs* let a component [hold some information that isn't used for rendering,](/learn/referencing-values-with-refs) like a DOM node or a timeout ID. Unlike with state, updating a ref does not re-render your component. Refs are an "escape hatch" from the React paradigm. They are useful when you need to work with non-React systems, such as the built-in browser APIs.
46+
*ref* 让一个组件 [持有一些不用于渲染的信息](/learn/referencing-values-with-refs),如 DOM 节点或一个 timeout ID。与 state 不同的是,更新 ref 并不会重新渲染你的组件。ref React 范式的一个“规避机制”。当你需要与非 React 系统一起工作时,它们很有用,比如内置的浏览器 API。
4747
48-
* [`useRef`](/reference/react/useRef) declares a ref. You can hold any value in it, but most often it's used to hold a DOM node.
49-
* [`useImperativeHandle`](/reference/react/useImperativeHandle) lets you customize the ref exposed by your component. This is rarely used.
48+
* [`useRef`](/reference/react/useRef) 声明一个 ref。你可以在其中保存任何值,但最常见的是它用来保存一个 DOM 节点。
49+
* [`useImperativeHandle`](/reference/react/useImperativeHandle) 可以让你自定义组件所暴露的 ref。一般很少使用。
5050
5151
```js
5252
function Form() {
@@ -56,11 +56,11 @@ function Form() {
5656
5757
---
5858
59-
## Effect Hooks {/*effect-hooks*/}
59+
## Effect Hook {/*effect-hooks*/}
6060
61-
*Effects* let a component [connect to and synchronize with external systems.](/learn/synchronizing-with-effects) This includes dealing with network, browser DOM, animations, widgets written using a different UI library, and other non-React code.
61+
*Effect* 让一个组件 [连接到外部系统并与之同步](/learn/synchronizing-with-effects)。这包括处理网络、浏览器、DOM、动画、使用不同 UI 库编写的 widgets 以及其他非 React 代码。
6262
63-
* [`useEffect`](/reference/react/useEffect) connects a component to an external system.
63+
* [`useEffect`](/reference/react/useEffect) 将一个组件连接到外部系统。
6464
6565
```js
6666
function ChatRoom({ roomId }) {
@@ -72,23 +72,23 @@ function ChatRoom({ roomId }) {
7272
// ...
7373
```
7474
75-
Effects are an "escape hatch" from the React paradigm. Don't use Effects to orchestrate the data flow of your application. If you're not interacting with an external system, [you might not need an Effect.](/learn/you-might-not-need-an-effect)
75+
Effect 是 React 范式的“规避机制”。不要用 Effect 来协调你的应用程序的数据流。如果你不与外部系统交互,[你可能不需要 Effect](/learn/you-might-not-need-an-effect)
7676
77-
There are two rarely used variations of `useEffect` with differences in timing:
77+
`useEffect` 有两个很少使用的变换形式,它们在时机上有一些差异:
7878
79-
* [`useLayoutEffect`](/reference/react/useLayoutEffect) fires before the browser repaints the screen. You can measure layout here.
80-
* [`useInsertionEffect`](/reference/react/useInsertionEffect) fires before React makes changes to the DOM. Libraries can insert dynamic CSS here.
79+
* [`useLayoutEffect`](/reference/react/useLayoutEffect) 在浏览器重新绘制屏幕前执行。在这里,你可以测量布局。
80+
* [`useInsertionEffect`](/reference/react/useInsertionEffect) React DOM 进行更改之前触发。在这里,库可以插入动态的 CSS
8181
8282
---
8383
84-
## Performance Hooks {/*performance-hooks*/}
84+
## 性能 Hook {/*performance-hooks*/}
8585
86-
A common way to optimize re-rendering performance is to skip unnecessary work. For example, you can tell React to reuse a cached calculation or to skip a re-render if the data has not changed since the previous render.
86+
优化重新渲染性能的一个常见方法就是跳过不必要的工作。比如,你可以告诉 React 重用一个缓存的计算结果,或者如果数据在上一次渲染后没有变化,就跳过这次重新渲染。
8787
88-
To skip calculations and unnecessary re-rendering, use one of these Hooks:
88+
你可以使用这些 Hook 跳过计算和不必要的重新渲染:
8989
90-
- [`useMemo`](/reference/react/useMemo) lets you cache the result of an expensive calculation.
91-
- [`useCallback`](/reference/react/useCallback) lets you cache a function definition before passing it down to an optimized component.
90+
* [`useMemo`](/reference/react/useMemo) 让你缓存一个代价非常高的计算结果。
91+
* [`useCallback`](/reference/react/useCallback) 让你在将一个函数定义传递给一个优化的组件之前缓存它。
9292
9393
```js
9494
function TodoList({ todos, tab, theme }) {
@@ -97,25 +97,25 @@ function TodoList({ todos, tab, theme }) {
9797
}
9898
```
9999
100-
Sometimes, you can't skip re-rendering because the screen actually needs to update. In that case, you can improve performance by separating blocking updates that must be synchronous (like typing into an input) from non-blocking updates which don't need to block the user interface (like updating a chart).
100+
有时,你不能跳过重新渲染,因为屏幕确实需要更新。在这种情况下,你可以通过将必须同步的阻塞更新(比如使用输入法输入内容)与不需要阻塞用户界面的非阻塞更新(比如更新图表)分开以提高性能。
101101
102-
To prioritize rendering, use one of these Hooks:
102+
要确定渲染的优先级,可以使用以下 Hook:
103103
104-
- [`useTransition`](/reference/react/useTransition) lets you mark a state transition as non-blocking and allow other updates to interrupt it.
105-
- [`useDeferredValue`](/reference/react/useDeferredValue) lets you defer updating a non-critical part of the UI and let other parts update first.
104+
* [`useTransition`](/reference/react/useTransition) 让你把一个状态转换标记为非阻塞,并允许其他更新中断它。
105+
* [`useDeferredValue`](/reference/react/useDeferredValue) 让你推迟更新用户界面的一个非关键部分,让其他部分更新。
106106
107107
---
108108
109-
## Other Hooks {/*other-hooks*/}
109+
## 其他 Hook {/*other-hooks*/}
110110
111-
These Hooks are mostly useful to library authors and aren't commonly used in the application code.
111+
这些 Hook 主要对库的作者有用,在应用代码中并不常用。
112112
113-
- [`useDebugValue`](/reference/react/useDebugValue) lets you customize the label React DevTools displays for your custom Hook.
114-
- [`useId`](/reference/react/useId) lets a component associate a unique ID with itself. Typically used with accessibility APIs.
115-
- [`useSyncExternalStore`](/reference/react/useSyncExternalStore) lets a component subscribe to an external store.
113+
* [`useDebugValue`](/reference/react/useDebugValue) 允许你在 React 开发者工具中为自定义 Hook 添加一个标签。
114+
* [`useId`](/reference/react/useId) 允许组件绑定一个唯一 ID。通常与可访问性 API 一起使用。
115+
* [`useSyncExternalStore`](/reference/react/useSyncExternalStore) 允许一个组件订阅一个外部 store
116116
117117
---
118118
119-
## Your own Hooks {/*your-own-hooks*/}
119+
## 自定义 Hook {/*your-own-hooks*/}
120120
121-
You can also [define your own custom Hooks](/learn/reusing-logic-with-custom-hooks#extracting-your-own-custom-hook-from-a-component) as JavaScript functions.
121+
你也可以在 JavaScript 函数中 [定义你自己的 Hook](/learn/reusing-logic-with-custom-hooks#extracting-your-own-custom-hook-from-a-component)

0 commit comments

Comments
 (0)