diff --git a/content/blog/2015-12-18-react-components-elements-and-instances.md b/content/blog/2015-12-18-react-components-elements-and-instances.md
index aea0411d0f..143f3d5e65 100644
--- a/content/blog/2015-12-18-react-components-elements-and-instances.md
+++ b/content/blog/2015-12-18-react-components-elements-and-instances.md
@@ -1,24 +1,24 @@
---
-title: "React Components, Elements, and Instances"
+title: "React 组件,元素和实例"
author: [gaearon]
---
-The difference between **components, their instances, and elements** confuses many React beginners. Why are there three different terms to refer to something that is painted on screen?
+许多 React 初学者对**组件、其实例以及元素**之间的区别感到困惑。为什么有三个不同的术语来指代屏幕上绘制的内容?
-## Managing the Instances {#managing-the-instances}
+## 管理实例 {#managing-the-instances}
-If you’re new to React, you probably only worked with component classes and instances before. For example, you may declare a `Button` *component* by creating a class. When the app is running, you may have several *instances* of this component on screen, each with its own properties and local state. This is the traditional object-oriented UI programming. Why introduce *elements*?
+如果你不熟悉 React,那么此前你可能仅仅工作用到过组件类和实例。例如,你可能通过新建一个 class 来声明 `Button` *组件*。当 app 运行起来以后,你可能会有若干个拥有自己属性和本地 state 的*实例*运行在屏幕上。这是传统的面向对象 UI 编程。那为什么要引入*元素*?
-In this traditional UI model, it is up to you to take care of creating and destroying child component instances. If a `Form` component wants to render a `Button` component, it needs to create its instance, and manually keep it up to date with any new information.
+在这些传统的 UI 模型中,需要由你来关心创建及销毁子组件们的实例。如果一个 `Form` 组件要渲染一个 `Button` 组件,那么它需要创建其实例并手动根据最新的信息使其保持同步。
```js
class Form extends TraditionalObjectOrientedView {
render() {
- // Read some data passed to the view
+ // 读取一些数据到当前视图
const { isSubmitted, buttonText } = this.attrs;
if (!isSubmitted && !this.button) {
- // Form is not yet submitted. Create the button!
+ // 表单还未提交。创建按钮!
this.button = new Button({
children: buttonText,
color: 'blue'
@@ -27,19 +27,19 @@ class Form extends TraditionalObjectOrientedView {
}
if (this.button) {
- // The button is visible. Update its text!
+ // 按钮可见。更新其文本!
this.button.attrs.children = buttonText;
this.button.render();
}
if (isSubmitted && this.button) {
- // Form was submitted. Destroy the button!
+ // 表单已提交。销毁按钮!
this.el.removeChild(this.button.el);
this.button.destroy();
}
if (isSubmitted && !this.message) {
- // Form was submitted. Show the success message!
+ // 表达已经提交。显示成功信息!
this.message = new Message({ text: 'Success!' });
this.el.appendChild(this.message.el);
}
@@ -47,21 +47,21 @@ class Form extends TraditionalObjectOrientedView {
}
```
-This is pseudocode, but it is more or less what you end up with when you write composite UI code that behaves consistently in an object-oriented way using a library like Backbone.
+虽然这是一段伪代码,但只要你在使用一个库(比如 Backbone)编写复合界面代码的同时,恪守面向对象的思想,最终代码多少都会变成这个样子。
-Each component instance has to keep references to its DOM node and to the instances of the children components, and create, update, and destroy them when the time is right. The lines of code grow as the square of the number of possible states of the component, and the parents have direct access to their children component instances, making it hard to decouple them in the future.
+每个组件实例都必须保持对 DOM 节点和子组件实例的引用,同时在正确的时机新建、更新、销毁它们。随着组件可能状态的平方式增长,代码行数也将增长。与此同时,父组件直接访问子组件实例也使得将来它们彼此之间更难解耦。
-So how is React different?
+所以 React 有何不同呢?
-## Elements Describe the Tree {#elements-describe-the-tree}
+## 元素描述了树 {#elements-describe-the-tree}
-In React, this is where the *elements* come to rescue. **An element is a plain object *describing* a component instance or DOM node and its desired properties.** It contains only information about the component type (for example, a `Button`), its properties (for example, its `color`), and any child elements inside it.
+这正是 React 希望*元素*施展拳脚之处。**元素是一个用来*描述*组件实例或 DOM 节点及其需要属性的普通对象**。它只包含组件类型(比如 `Button`),其属性(比如`color`)以及所有其下子元素的相关信息。
-An element is not an actual instance. Rather, it is a way to tell React what you *want* to see on the screen. You can’t call any methods on the element. It’s just an immutable description object with two fields: `type: (string | ReactClass)` and `props: Object`[^1].
+一个元素不是一个确切的实例。他是一种告诉 React 你*想要*在屏幕上看到什么的方法。你不能在元素上调用任何方法。它只是一个携有 `type: (string | ReactClass)` 和 `props: Object`[^1] 字段的不可变描述对象。
-### DOM Elements {#dom-elements}
+### DOM 元素 {#dom-elements}
-When an element’s `type` is a string, it represents a DOM node with that tag name, and `props` correspond to its attributes. This is what React will render. For example:
+当一个元素的 `type` 是字符串时,它代表了一个具有该标签名称的 DOM 节点。`props` 对应于它的属性。React 这就是 React 将呈现的内容。举个例子:
```js
{
@@ -78,7 +78,7 @@ When an element’s `type` is a string, it represents a DOM node with that tag n
}
```
-This element is just a way to represent the following HTML as a plain object:
+这个元素只不过是一种将下面这段 HTML 表示成一个普通对象的方法。
```html
```
-Note how elements can be nested. By convention, when we want to create an element tree, we specify one or more child elements as the `children` prop of their containing element.
+注意元素是如何嵌套的。按照惯例,当我们要创建一棵 element tree 时,我们指定一或多个子元素作为其 `children` 成员。
-What’s important is that both child and parent elements are *just descriptions and not the actual instances*. They don’t refer to anything on the screen when you create them. You can create them and throw them away, and it won’t matter much.
+重要的是子元素和父元素*仅仅作为描述而不是真正的实例*。当你创建了它们,它们并不代表任何屏幕上的东西。你可以创建、丢弃它们,不必担心什么。
-React elements are easy to traverse, don’t need to be parsed, and of course they are much lighter than the actual DOM elements—they’re just objects!
+React 元素易于遍历,无需解析。此外它们比起真实的 DOM 元素更轻——它们只是对象!
-### Component Elements {#component-elements}
+### 组件元素 {#component-elements}
-However, the `type` of an element can also be a function or a class corresponding to a React component:
+然而,元素的 `type` 究竟是一个函数还是一个类则视 React 组件而定:
```js
{
@@ -108,11 +108,11 @@ However, the `type` of an element can also be a function or a class correspondin
}
```
-This is the core idea of React.
+这是 React 的核心思想。
-**An element describing a component is also an element, just like an element describing the DOM node. They can be nested and mixed with each other.**
+**一个用于描述组件的元素也是一个元素,就像一个用于描述 DOM 节点的元素一样。它们可以彼此嵌套,互相混合。**
-This feature lets you define a `DangerButton` component as a `Button` with a specific `color` property value without worrying about whether `Button` renders to a DOM `