File tree Expand file tree Collapse file tree 1 file changed +2
-2
lines changed Expand file tree Collapse file tree 1 file changed +2
-2
lines changed Original file line number Diff line number Diff line change @@ -264,7 +264,7 @@ props 和 state 是不同的,但它们可以共同工作。父组件将经常
264
264
3 . 决定 state 应该被放置于哪里:
265
265
1 . 通常情况下,你可以直接放置 state 于它们共同的父组件。
266
266
2 . 你也可以将 state 放置于它们父组件上层的组件。
267
- 3 . 如果你找不到一个有意义拥有这个 state 的地方,单独创建一个新的组件去管理这个 state,并将它添加到它们父组件上层的某个地方。
267
+ 3 . 如果你找不到一个合适来放这个 state 的地方,单独创建一个新的组件去管理这个 state,并将它添加到它们父组件上层的某个地方。
268
268
269
269
在之前的步骤中,你已在应用程序中创建了两个 state:输入框文本和复选框的值。在这个例子中,它们总在一起展示,将其视为一个 state 非常简单。
270
270
@@ -468,7 +468,7 @@ function SearchBar({ filterText, inStockOnly }) {
468
468
469
469
目前你的应用程序可以带着 props 和 state 随着层级结构进行渲染。但是为了支持通过用户输入来改变 state,你需要让数据反向传输:深层结构的表单组件需要更新 ` FilterableProductTable` 的 state。
470
470
471
- React 使数据流显式展示,是与双向数据绑定相比,需要更多的输入 。如果你尝试在上述的例子中输入或者勾选复选框,发现 React 忽视了你的输入。这点是有意为之的。通过 ` < input value= {filterText} / > ` ,已经设置了 ` input` 的 ` value` 属性,使之恒等于从 ` FilterableProductTable` 传递的 ` filterText` state。只要 ` filterText` state 不设置,(输入框的)输入就不会改变。
471
+ React 使数据流变得明确,但比双向数据绑定需要多写一些代码 。如果你尝试在上述的例子中输入或者勾选复选框,发现 React 忽视了你的输入。这点是有意为之的。通过 ` < input value= {filterText} / > ` ,已经设置了 ` input` 的 ` value` 属性,使之恒等于从 ` FilterableProductTable` 传递的 ` filterText` state。只要 ` filterText` state 不设置,(输入框的)输入就不会改变。
472
472
473
473
当用户更改表单输入时,state 将更新以反映这些更改。state 由 ` FilterableProductTable` 所拥有,所以只有它可以调用 ` setFilterText` 和 ` setInStockOnly` 。使 ` SearchBar` 更新 ` FilterableProductTable` 的 state,需要将这些函数传递到 ` SearchBar` :
474
474
You can’t perform that action at this time.
0 commit comments