Skip to content

Commit 80adf62

Browse files
committed
fix: doc
1 parent 715977a commit 80adf62

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

content/docs/typechecking-with-proptypes.md

+11-10
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,17 @@ MyComponent.propTypes = {
7575
// 可以指定一个数组由某一类型的元素组成
7676
optionalArrayOf: PropTypes.arrayOf(PropTypes.number),
7777

78-
// 一个指定类型属性构成的对象
78+
// 可以指定一个对象由某一类型的值组成
7979
optionalObjectOf: PropTypes.objectOf(PropTypes.number),
8080

81-
// 一个指定属性及其类型的对象
81+
// 可以指定一个对象由特定的类型值组成
8282
optionalObjectWithShape: PropTypes.shape({
8383
color: PropTypes.string,
8484
fontSize: PropTypes.number
8585
}),
8686

87-
// 你可以在任何 PropTypes 属性后面加上 `isRequired` ,确保这个属性父组件没有提供时,会打印警告信息。
87+
// 你可以在任何 PropTypes 属性后面加上 `isRequired` ,确保
88+
// 这个 prop 没有被提供时,会打印警告信息。
8889
requiredFunc: PropTypes.func.isRequired,
8990

9091
// 任意类型的数据
@@ -104,7 +105,8 @@ MyComponent.propTypes = {
104105
// 你也可以提供一个自定义的 `arrayOf` 或 `objectOf` 验证器。
105106
// 它应该在验证失败时返回一个 Error 对象。
106107
// 验证器将验证数组或对象中的每个值。验证器的前两个参数
107-
// 第一个是数组或对象本身,第二个是他们的键。
108+
// 第一个是数组或对象本身
109+
// 第二个是他们当前的键。
108110
customArrayProp: PropTypes.arrayOf(function(propValue, key, componentName, location, propFullName) {
109111
if (!/matchme/.test(propValue[key])) {
110112
return new Error(
@@ -116,10 +118,9 @@ MyComponent.propTypes = {
116118
};
117119
```
118120

119-
### 限制一个元素 {#requiring-single-child}
121+
### 限制单个元素 {#requiring-single-child}
120122

121-
使用 `PropTypes.element`
122-
你可以指定 children 只有一个元素作为传递到组件。
123+
你可以通过 `PropTypes.element` 来确保传递给组件的 children 中只包含一个元素。
123124

124125
```javascript
125126
import PropTypes from 'prop-types';
@@ -141,7 +142,7 @@ MyComponent.propTypes = {
141142
};
142143
```
143144

144-
### 属性默认值 {#default-prop-values}
145+
### 默认 Prop 值 {#default-prop-values}
145146

146147
您可以通过配置特定的 `defaultProps` 属性来定义 `props` 的默认值:
147148

@@ -166,7 +167,7 @@ ReactDOM.render(
166167
);
167168
```
168169

169-
如果你正在使用像 [transform-class-properties](https://babeljs.io/docs/plugins/transform-class-properties/) 的 Babel 转换工具,你也可以在 React 组件类中声明 `defaultProps` 作为静态属性。此语法提案还没有最终确定,在浏览器中需要进行编译才能使用。要了解更多信息,请查阅 [class fields proposal](https://github.com/tc39/proposal-class-fields)
170+
如果你正在使用像 [transform-class-properties](https://babeljs.io/docs/plugins/transform-class-properties/) 的 Babel 转换工具,你也可以在 React 组件类中声明 `defaultProps` 作为静态属性。此语法提案还没有最终确定,需要进行编译后才能在浏览器中运行。要了解更多信息,请查阅 [class fields proposal](https://github.com/tc39/proposal-class-fields)
170171

171172
```javascript
172173
class Greeting extends React.Component {
@@ -182,4 +183,4 @@ class Greeting extends React.Component {
182183
}
183184
```
184185

185-
`defaultProps` 用于确保 `this.props.name` 在父组件没有指定值时,有一个默认值。`propTypes` 类型检查发生在 `defaultProps` 赋值后,所以类型检查也适用于 `defaultProps`
186+
`defaultProps` 用于确保 `this.props.name` 在父组件没有指定其值时,有一个默认值。`propTypes` 类型检查发生在 `defaultProps` 赋值后,所以类型检查也适用于 `defaultProps`

0 commit comments

Comments
 (0)