Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(cn): translate content/docs/reference-glossary.md into Chinese #155

Merged
merged 8 commits into from
Mar 14, 2019
Merged
116 changes: 58 additions & 58 deletions content/docs/reference-glossary.md
Original file line number Diff line number Diff line change
@@ -1,73 +1,73 @@
---
id: glossary
title: Glossary of React Terms
title: React 术语词汇表
layout: docs
category: Reference
permalink: docs/glossary.html

---

## Single-page Application
## 单页面应用 {#single-page-application}

A single-page application is an application that loads a single HTML page and all the necessary assets (such as JavaScript and CSS) required for the application to run. Any interactions with the page or subsequent pages do not require a round trip to the server which means the page is not reloaded.
单页面应用(single-page application),是一个应用程序,它可以加载单个 HTML 页面,以及运行应用程序所需的所有必要资源(例如 JavaScript CSS)。与页面或后续页面的任何交互,都不再需要往返 server 加载资源,即页面不会重新加载。

Though you may build a single-page application in React, it is not a requirement. React can also be used for enhancing small parts of existing websites with additional interactivity. Code written in React can coexist peacefully with markup rendered on the server by something like PHP, or with other client-side libraries. In fact, this is exactly how React is being used at Facebook.
你可以使用 React 来构建单页应用程序,但不是必须如此。React 还可用于增强现有网站的小部分,使其增加额外交互。用 React 编写的代码,可以与服务器端渲染的标记(例如 PHP)或其他客户端库和平共处。实际上,这也正是 Facebook 内部使用 React 的方式。

## ES6, ES2015, ES2016, etc
## ES6, ES2015, ES2016 等 {#es6-es2015-es2016-etc}

These acronyms all refer to the most recent versions of the ECMAScript Language Specification standard, which the JavaScript language is an implementation of. The ES6 version (also known as ES2015) includes many additions to the previous versions such as: arrow functions, classes, template literals, `let` and `const` statements. You can learn more about specific versions [here](https://en.wikipedia.org/wiki/ECMAScript#Versions).
这些首字母缩写都是指 ECMAScript 语言规范标准的最新版本,JavaScript 语言是此标准的一个实现。其中 ES6 版本(也称为 ES2015)包括对前面版本的许多补充,例如:箭头函数、class、模板字面量、`let` `const` 语句。可以在[这里](https://en.wikipedia.org/wiki/ECMAScript#Versions)了解此规范特定版本的详细信息。

## Compilers
## compiler(编译器) {#compilers}

A JavaScript compiler takes JavaScript code, transforms it and returns JavaScript code in a different format. The most common use case is to take ES6 syntax and transform it into syntax that older browsers are capable of interpreting. [Babel](https://babeljs.io/) is the compiler most commonly used with React.
JavaScript compiler 接收 JavaScript 代码,然后对其进行转换,最终返回不同格式的 JavaScript 代码。最为常见的使用示例是,接收 ES6 语法,然后将其转换为旧版本浏览器能够解释执行的语法。[Babel](https://babeljs.io/) 是 React 最常用的 compiler。

## Bundlers
## bundler(打包工具) {#bundlers}

Bundlers take JavaScript and CSS code written as separate modules (often hundreds of them), and combine them together into a few files better optimized for the browsers. Some bundlers commonly used in React applications include [Webpack](https://webpack.js.org/) and [Browserify](http://browserify.org/).
bundler 会接收写成单独模块(通常有数百个)的 JavaScript CSS 代码,然后将它们组合在一起,最终生成出一些为浏览器优化的文件。常用的打包 React 应用的工具有 [webpack](https://webpack.js.org/) [Browserify](http://browserify.org/)

## Package Managers
## package 管理工具 {#package-managers}

Package managers are tools that allow you to manage dependencies in your project. [npm](https://www.npmjs.com/) and [Yarn](http://yarnpkg.com/) are two package managers commonly used in React applications. Both of them are clients for the same npm package registry.
package 管理工具,是帮助你管理项目依赖的工具。[npm](https://www.npmjs.com/) [Yarn](https://yarnpkg.com/) 是两个常用的管理 React 应用依赖的 package 管理工具。它们都是使用了相同 npm package registry 的客户端。

## CDN
## CDN {#cdn}

CDN stands for Content Delivery Network. CDNs deliver cached, static content from a network of servers across the globe.
CDN 代表内容分发网络(Content Delivery Network)。CDN 会通过一个遍布全球的服务器网络来分发缓存的静态内容。

## JSX
## JSX {#jsx}

JSX is a syntax extension to JavaScript. It is similar to a template language, but it has full power of JavaScript. JSX gets compiled to `React.createElement()` calls which return plain JavaScript objects called "React elements". To get a basic introduction to JSX [see the docs here](/docs/introducing-jsx.html) and find a more in-depth tutorial on JSX [here](/docs/jsx-in-depth.html).
JSX 是一个 JavaScript 语法扩展。它类似于模板语言,但它具有 JavaScript 的全部能力。JSX 最终会被编译为 `React.createElement()` 函数调用,返回称为 “React 元素” 的普通 JavaScript 对象。通过[查看这篇文档](/docs/introducing-jsx.html)获取 JSX 语法的基本介绍,在[这篇文档]中可以找到 JSX 语法的更多深入教程。

React DOM uses camelCase property naming convention instead of HTML attribute names. For example, `tabindex` becomes `tabIndex` in JSX. The attribute `class` is also written as `className` since `class` is a reserved word in JavaScript:
React DOM 使用 camelCase(驼峰式命名)来定义属性的名称,而不使用 HTML 属性名称的命名约定。例如,HTML `tabindex` 属性变成了 JSX 的 `tabIndex`。而 `class` 属性则变为 `className`,这是因为 `class` JavaScript 中的保留字:

```js
const name = 'Clementine';
ReactDOM.render(
<h1 className="hello">My name is {name}!</h1>,
document.getElementById('root')
);
```
```

## [Elements](/docs/rendering-elements.html)
## [元素](/docs/rendering-elements.html) {#elements}

React elements are the building blocks of React applications. One might confuse elements with a more widely known concept of "components". An element describes what you want to see on the screen. React elements are immutable.
React 元素是构成 React 应用的基础砖块。人们可能会把元素与广为人知的“组件”概念相互混淆。元素描述了你在屏幕上想看到的内容。React 元素是不可变对象。

```js
const element = <h1>Hello, world</h1>;
```

Typically, elements are not used directly, but get returned from components.
通常我们不会直接使用元素,而是从组件中返回元素。

## [Components](/docs/components-and-props.html)
## [组件](/docs/components-and-props.html) {#components}

React components are small, reusable pieces of code that return a React element to be rendered to the page. The simplest version of React component is a plain JavaScript function that returns a React element:
React 组件是可复用的小的代码片段,它们返回要在页面中渲染的 React 元素。React 组件的最简版本是,一个返回 React 元素的普通 JavaScript 函数:

```js
function Welcome(props) {
return <h1>Hello, {props.name}</h1>;
}
```

Components can also be ES6 classes:
组件也可以使用 ES6 的 class 编写:

```js
class Welcome extends React.Component {
Expand All @@ -77,38 +77,38 @@ class Welcome extends React.Component {
}
```

Components can be broken down into distinct pieces of functionality and used within other components. Components can return other components, arrays, strings and numbers. A good rule of thumb is that if a part of your UI is used several times (Button, Panel, Avatar), or is complex enough on its own (App, FeedStory, Comment), it is a good candidate to be a reusable component. Component names should also always start with a capital letter (`<Wrapper/>` **not** `<wrapper/>`). See [this documentation](/docs/components-and-props.html#rendering-a-component) for more information on rendering components.
组件可被拆分为不同的功能片段,这些片段可以在其他组件中使用。组件可以返回其他组件、数组、字符串和数字。根据经验来看,如果 UI 中有一部分被多次使用(ButtonPanelAvatar),或者组件本身就足够复杂(AppFeedStoryComment),那么它就是一个可复用组件的候选项。组件名称应该始终以大写字母开头(`<Wrapper/>` **而不是** `<wrapper/>`)。有关渲染组件的更多信息,请参阅[这篇文档](/docs/components-and-props.html#rendering-a-component)

### [`props`](/docs/components-and-props.html)
### [`props`](/docs/components-and-props.html) {#props}

`props` are inputs to a React component. They are data passed down from a parent component to a child component.
`props` React 组件的输入。它们是从父组件向下传递给子组件的数据。

Remember that `props` are readonly. They should not be modified in any way:
记住,`props` 是只读的。不应以任何方式修改它们:

```js
// Wrong!
// 错误做法!
props.number = 42;
```

If you need to modify some value in response to user input or a network response, use `state` instead.
如果你想要修改某些值,以响应用户输入或网络响应,请使用 `state` 来作为替代。

### `props.children`
### `props.children` {#propschildren}

`props.children` is available on every component. It contains the content between the opening and closing tags of a component. For example:
每个组件都可以获取到 `props.children`。它包含组件的开始标签和结束标签之间的内容。例如:

```js
<Welcome>Hello world!</Welcome>
```

The string `Hello world!` is available in `props.children` in the `Welcome` component:
在 `Welcome` 组件中获取 `props.children`,就可以得到字符串 `Hello world!`:

```js
function Welcome(props) {
return <p>{props.children}</p>;
}
```

For components defined as classes, use `this.props.children`:
对于 class 组件,请使用 `this.props.children` 来获取:

```js
class Welcome extends React.Component {
Expand All @@ -118,49 +118,49 @@ class Welcome extends React.Component {
}
```

### [`state`](/docs/state-and-lifecycle.html#adding-local-state-to-a-class)
### [`state`](/docs/state-and-lifecycle.html#adding-local-state-to-a-class) {#state}

A component needs `state` when some data associated with it changes over time. For example, a `Checkbox` component might need `isChecked` in its state, and a `NewsFeed` component might want to keep track of `fetchedPosts` in its state.
当组件中的一些数据在某些时刻发生变化时,这时就需要使用 `state` 来跟踪状态。例如,`Checkbox` 组件可能需要 `isChecked` 状态,而 `NewsFeed` 组件可能需要跟踪 `fetchedPosts` 状态。

The most important difference between `state` and `props` is that `props` are passed from a parent component, but `state` is managed by the component itself. A component cannot change its `props`, but it can change its `state`. To do so, it must call `this.setState()`. Only components defined as classes can have state.
`state` `props` 之间最重要的区别是:`props` 由父组件传入,而 `state` 由组件本身管理。组件不能修改 `props`,但它可以修改 `state`。如果要修改 `state`,必须调用 `this.setState()`。只有 class 组件才具有 state

For each particular piece of changing data, there should be just one component that "owns" it in its state. Don't try to synchronize states of two different components. Instead, [lift it up](/docs/lifting-state-up.html) to their closest shared ancestor, and pass it down as props to both of them.
对于所有变化数据中的每个特定部分,只应该由一个组件在其 state 中“持有”它。不要试图同步来自于两个不同组件的 state。相反,应当将其[提升](/docs/lifting-state-up.html)到最近的共同祖先组件中,并将这个 state 作为 props 传递到两个子组件。

## [Lifecycle Methods](/docs/state-and-lifecycle.html#adding-lifecycle-methods-to-a-class)
## [生命周期方法](/docs/state-and-lifecycle.html#adding-lifecycle-methods-to-a-class) {#lifecycle-methods}

Lifecycle methods are custom functionality that gets executed during the different phases of a component. There are methods available when the component gets created and inserted into the DOM ([mounting](/docs/react-component.html#mounting)), when the component updates, and when the component gets unmounted or removed from the DOM.
生命周期方法,用于在组件不同阶段执行自定义功能。在组件被创建并插入到 DOM 时(即[挂载中阶段(mounting](/docs/react-component.html#mounting)),组件更新时,组件取消挂载或从 DOM 中删除时,都有可以使用的生命周期方法。

## [Controlled](/docs/forms.html#controlled-components) vs. [Uncontrolled Components](/docs/uncontrolled-components.html)
## [受控组件](/docs/forms.html#controlled-components) vs [非受控组件](/docs/uncontrolled-components.html)

React has two different approaches to dealing with form inputs.
React 有两种不同的方式来处理表单输入。

An input form element whose value is controlled by React is called a *controlled component*. When a user enters data into a controlled component a change event handler is triggered and your code decides whether the input is valid (by re-rendering with the updated value). If you do not re-render then the form element will remain unchanged.
如果一个 input 表单元素的值是由 React 控制,就其称为*受控组件*。当用户将数据输入到受控组件时,会触发修改状态的事件处理器,这时由你的代码来决定此输入是否有效(如果有效就使用更新后的值重新渲染)。如果不重新渲染,则表单元素将保持不变。

An *uncontrolled component* works like form elements do outside of React. When a user inputs data into a form field (an input box, dropdown, etc) the updated information is reflected without React needing to do anything. However, this also means that you can't force the field to have a certain value.
一个*非受控组件*,就像是运行在 React 体系之外的表单元素。当用户将数据输入到表单字段(例如 inputdropdown 等)时,React 不需要做任何事情就可以映射更新后的信息。然而,这也意味着,你无法强制给这个表单字段设置一个特定值。

In most cases you should use controlled components.
在大多数情况下,你应该使用受控组件。

## [Keys](/docs/lists-and-keys.html)
## [key](/docs/lists-and-keys.html) {#keys}

A "key" is a special string attribute you need to include when creating arrays of elements. Keys help React identify which items have changed, are added, or are removed. Keys should be given to the elements inside an array to give the elements a stable identity.
“key” 是在创建元素数组时,需要用到的一个特殊字符串属性。key 帮助 React 识别出被修改、添加或删除的 item。应当给数组内的每个元素都设定 key,以使元素具有固定身份标识。

Keys only need to be unique among sibling elements in the same array. They don't need to be unique across the whole application or even a single component.
只需要保证,在同一个数组中的兄弟元素之间的 key 是唯一的。而不需要在整个应用程序甚至单个组件中保持唯一。

Don't pass something like `Math.random()` to keys. It is important that keys have a "stable identity" across re-renders so that React can determine when items are added, removed, or re-ordered. Ideally, keys should correspond to unique and stable identifiers coming from your data, such as `post.id`.
不要将 `Math.random()` 之类的值传递给 key。重要的是,在前后两次渲染之间的 key 要具有“固定身份标识”的特点,以便 React 可以在添加、删除或重新排序 item 时,前后对应起来。理想情况下,key 应该从数据中获取,对应着唯一且固定的标识符,例如 `post.id`

## [Refs](/docs/refs-and-the-dom.html)
## [ref](/docs/refs-and-the-dom.html) {#refs}

React supports a special attribute that you can attach to any component. The `ref` attribute can be an object created by [`React.createRef()` function](/docs/react-api.html#reactcreateref) or a callback function, or a string (in legacy API). When the `ref` attribute is a callback function, the function receives the underlying DOM element or class instance (depending on the type of element) as its argument. This allows you to have direct access to the DOM element or component instance.
React 支持一个特殊的、可以附加到任何组件上的 `ref` 属性。此属性可以是一个由 [`React.createRef()` 函数](/docs/react-api.html#reactcreateref)创建的对象、或者一个回调函数、或者一个字符串(遗留 API)。当 `ref` 属性是一个回调函数时,此函数会(根据元素的类型)接收底层 DOM 元素或 class 实例作为其参数。这能够让你直接访问 DOM 元素或组件实例。

Use refs sparingly. If you find yourself often using refs to "make things happen" in your app, consider getting more familiar with [top-down data flow](/docs/lifting-state-up.html).
谨慎使用 ref。如果你发现自己经常使用 ref 来在应用中“实现想要的功能”,你可以考虑去了解一下[自上而下的数据流](/docs/lifting-state-up.html)

## [Events](/docs/handling-events.html)
## [事件](/docs/handling-events.html) {#events}

Handling events with React elements has some syntactic differences:
使用 React 元素处理事件时,有一些语法上差异:

* React event handlers are named using camelCase, rather than lowercase.
* With JSX you pass a function as the event handler, rather than a string.
* React 事件处理器使用 camelCase(驼峰式命名)而不使用小写命名。
* 通过 JSX,你可以直接传入一个函数,而不是传入一个字符串,来作为事件处理器。

## [Reconciliation](/docs/reconciliation.html)
## [协调](/docs/reconciliation.html) {#reconciliation}

When a component's props or state change, React decides whether an actual DOM update is necessary by comparing the newly returned element with the previously rendered one. When they are not equal, React will update the DOM. This process is called "reconciliation".
当组件的 props state 发生变化时,React 通过将最新返回的元素与原先渲染的元素进行比较,来决定是否有必要进行一次实际的 DOM 更新。当它们不相等时,React 才会更新 DOM。这个过程被称为“协调”。