Revert "Remove setProps and replaceProps completely" (#7039)
Paul O’Shannessy committed
Jun 14, 2016 at 15:02 UTC
6e8c2fb828ca448854ce434bbd319968a84f5c4d
8 files changed
+156
-1
docs/docs/ref-02-component-api.it-IT.md
+37
@@ -92,3 +92,40 @@ boolean isMounted()
92
> Nota:
93
>
94
> Questo metodo non è disponibile il componenti `class` ES6 che estendono `React.Component`. Potrebbe essere eliminato del tutto in una versione futura di React.
95
+
96
+
97
+### setProps
98
+
99
+```javascript
100
+void setProps(
101
+ object nextProps,
102
+ [function callback]
103
+)
104
+```
105
+
106
+Quando stai integrando con un'applicazione JavaScript esterna puoi voler segnalare un cambiamento a un componente React il cui rendering è stato effettuato con `ReactDOM.render()`.
107
+
108
+Chiamare `setProps()` su un componente al livello radice cambierà le sue proprietà e scatenerà un ri-rendering. Inoltre, puoi fornire una funzione callback opzionale che verrà eseguita quando `setProps` ha terminato e il rendering del componente è terminato.
109
+
110
+> Nota:
111
+>
112
+> Quando possibile, l'approccio dichiarativo di invocare nuovamente `ReactDOM.render()` sullo stesso nodo è preferibile. Quest'ultimo tende a rendere gli aggiornamenti più comprensibili. (Non vi è una differenza significativa di prestazioni tra i due approcci.)
113
+>
114
+> Questo metodo può essere chiamato soltanto su un componente al livello radice. Ovvero, è disponibile soltanto sul componente passato direttamente a `ReactDOM.render()` e nessuno dei suoi figli. Se il tuo intento è usare `setProps()` su un componente figlio, approfitta degli aggiornamenti reattivi e passa la nuova proprietà al componente figlio quando viene creato in `render()`.
115
+>
116
+> Questo metodo non è disponibile il componenti `class` ES6 che estendono `React.Component`. Potrebbe essere eliminato del tutto in una versione futura di React.
117
+
118
+### replaceProps
119
+
120
+```javascript
121
+void replaceProps(
122
+ object nextProps,
123
+ [function callback]
124
+)
125
+```
126
+
127
+Come `setProps()` ma elimina ogni proprietà preesistente anziché riunire i due oggetti.
128
+
129
+> Nota:
130
+>
131
+> Questo metodo non è disponibile il componenti `class` ES6 che estendono `React.Component`. Potrebbe essere eliminato del tutto in una versione futura di React.
docs/docs/ref-02-component-api.ko-KR.md
+38
@@ -93,3 +93,41 @@ boolean isMounted()
93
> 주의:
94
>
95
> 이 메소드는 `React.Component`를 확장한 ES6 `class` 컴포넌트에서는 사용할 수 없습니다. React의 미래 버전에서 이는 완전히 사라지게 될 것입니다.
96
+
97
+
98
+### setProps
99
+
100
+```javascript
101
+void setProps(
102
+ object nextProps,
103
+ [function callback]
104
+)
105
+```
106
+
107
+외부 JavaScript 애플리케이션과 연동하는 경우 `ReactDOM.render()`로 렌더링된 React 컴포넌트에 변경을 알리고 싶을 때가 있습니다.
108
+
109
+최상위 컴포넌트에서 `setProps()`를 호출하면 프로퍼티를 변경하고 렌더를 다시 발생합니다. 거기에 콜백 함수를 넘기면 `setProps`가 완료되고 컴포넌트가 다시 렌더링된 다음에 한번 호출됩니다.
110
+
111
+> 주의:
112
+>
113
+> 가능하다면 이것 대신 `ReactDOM.render()`를 같은 노드에서 다시 호출하는 선언적인 방법이 더 바람직합니다. 그렇게 하는 편이 업데이트에 대해 생각하는 것을 쉽게 만듭니다. (두가지 방식에 눈에 띄는 성능 차이는 없습니다.)
114
+>
115
+> 이 메소드는 최상위 컴포넌트에만 호출 가능합니다. 다시 말해, `ReactDOM.render()`에 바로 넘긴 컴포넌트에서만 사용할 수 있고 자식에서는 불가능합니다. 자식 컴포넌트에 `setProps()`를 사용하고 싶다면, 그 대신 반응적인 업데이트의 장점을 활용하여 `render()` 안에서 자식 컴포넌트를 만들 때 새로운 prop을 넘기세요.
116
+>
117
+> 이 메소드는 `React.Component`를 확장한 ES6 `class` 컴포넌트에서는 사용할 수 없습니다. React의 미래 버전에서 이는 완전히 사라지게 될 것입니다.
118
+
119
+
120
+### replaceProps
121
+
122
+```javascript
123
+void replaceProps(
124
+ object nextProps,
125
+ function callback]
126
+)
127
+```
128
+
129
+`setProps()`와 비슷하지만 두 객체를 합치는 대신 이전에 존재하던 props를 삭제합니다.
130
+
131
+> 주의:
132
+>
133
+> 이 메소드는 `React.Component`를 확장한 ES6 `class` 컴포넌트에서는 사용할 수 없습니다. React의 미래 버전에서 이는 완전히 사라지게 될 것입니다.
docs/docs/ref-02-component-api.md
+37
@@ -92,3 +92,40 @@ boolean isMounted()
92
> Note:
93
>
94
> This method is not available on ES6 `class` components that extend `React.Component`. It will likely be removed entirely in a future version of React, so you might as well [start migrating away from isMounted() now](/react/blog/2015/12/16/ismounted-antipattern.html).
95
+
96
+
97
+### setProps
98
+
99
+```javascript
100
+void setProps(
101
+ object nextProps,
102
+ [function callback]
103
+)
104
+```
105
+
106
+When you're integrating with an external JavaScript application you may want to signal a change to a React component rendered with `ReactDOM.render()`.
107
+
108
+Calling `setProps()` on a root-level component will change its properties and trigger a re-render. In addition, you can supply an optional callback function that is executed once `setProps` is completed and the component is re-rendered.
109
+
110
+> Note:
111
+>
112
+> This method is deprecated and will be removed soon. This method is not available on ES6 `class` components that extend `React.Component`. Instead of calling `setProps`, try invoking ReactDOM.render() again with the new props. For additional notes, see our [blog post about using the Top Level API](/react/blog/2015/10/01/react-render-and-top-level-api.html)
113
+>
114
+> When possible, the declarative approach of calling `ReactDOM.render()` again on the same node is preferred instead. It tends to make updates easier to reason about. (There's no significant performance difference between the two approaches.)
115
+>
116
+> This method can only be called on a root-level component. That is, it's only available on the component passed directly to `ReactDOM.render()` and none of its children. If you're inclined to use `setProps()` on a child component, instead take advantage of reactive updates and pass the new prop to the child component when it's created in `render()`.
117
+
118
+### replaceProps
119
+
120
+```javascript
121
+void replaceProps(
122
+ object nextProps,
123
+ [function callback]
124
+)
125
+```
126
+
127
+Like `setProps()` but deletes any pre-existing props instead of merging the two objects.
128
+
129
+> Note:
130
+>
131
+> This method is deprecated and will be removed soon. This method is not available on ES6 `class` components that extend `React.Component`. Instead of calling `replaceProps`, try invoking ReactDOM.render() again with the new props. For additional notes, see our [blog post about using the Top Level API](/react/blog/2015/10/01/react-render-and-top-level-api.html)
docs/docs/ref-02-component-api.zh-CN.md
+37
@@ -92,3 +92,40 @@ boolean isMounted()
92
> 注意:
93
>
94
> 这个方法在从 `React.Component` 扩展的 ES6 `class` 组件里不可用。它也许会在未来的 React 版本中被完全移除,所以你也要移除它 [start migrating away from isMounted() now](/react/blog/2015/12/16/ismounted-antipattern.html)
95
+
96
+
97
+### setProps
98
+
99
+```javascript
100
+void setProps(
101
+ object nextProps,
102
+ [function callback]
103
+)
104
+```
105
+
106
+当和一个外部的 JavaScript 应用整合的时候,你也许会想用 `ReactDOM.render()` 给 React 组件标示一个改变。
107
+
108
+在根组件上调用 `setProps()` 会改变他的属性并触发一次重绘。另外,你可以提供一个可选的回调函数,一旦 `setProps` 完成并且组件被重绘它就执行。
109
+
110
+> 注意:
111
+>
112
+> 这个方法被弃用了并会很快移除.这个方法在从 `React.Component` 扩展的 ES6 `class` 组件里不可用. 取代调用 `setProps`,试着以新的 props 再次调用 `ReactDOM.render()`. 更多的注意事项,见我们的[blog post about using the Top Level API](/react/blog/2015/10/01/react-render-and-top-level-api.html)
113
+>
114
+> 如果可能,上述的在同一个节点上再次调用 `ReactDOM.render()` 的方法是优先替代的。它往往使更新更容易理解。(两种方法并没有显著的性能区别。)
115
+>
116
+> 这个方法仅能在根组件上被调用。也就是说,它仅在直接传给 `ReactDOM.render()` 的组件上可用,在它的子级上不可用。如果你倾向于在子组件上使用 `setProps()`,不要利用响应式更新,而是当子组件在 `render()` 中创建的时候传入新的 prop 到子组件中。
117
+
118
+### replaceProps
119
+
120
+```javascript
121
+void replaceProps(
122
+ object nextProps,
123
+ [function callback]
124
+)
125
+```
126
+
127
+类似于 `setProps()`,但是删除任何先前存在的 props,而不是合并这两个对象。
128
+
129
+> 注意:
130
+>
131
+> 这个方法被弃用了并会很快移除.这个方法在从 `React.Component` 扩展的 ES6 `class` 组件里不可用. 取代调用 `replaceProps`,试着以新的 props 再次调用 `ReactDOM.render()`. 更多的注意事项,见我们的[blog post about using the Top Level API](/react/blog/2015/10/01/react-render-and-top-level-api.html)
src/isomorphic/modern/class/__tests__/ReactCoffeeScriptClass-test.coffee
+2
@@ -362,6 +362,8 @@ describe 'ReactCoffeeScriptClass', ->
362
test Inner(name: 'foo'), 'DIV', 'foo'
363
expect(-> instance.replaceState {}).toThrow()
364
expect(-> instance.isMounted()).toThrow()
365
+ expect(-> instance.setProps name: 'bar').toThrow()
366
+ expect(-> instance.replaceProps name: 'bar').toThrow()
367
expect(console.error.calls.count()).toBe 2
368
expect(console.error.calls.argsFor(0)[0]).toContain(
369
'replaceState(...) is deprecated in plain JavaScript React classes'
src/isomorphic/modern/class/__tests__/ReactES6Class-test.js
+2
@@ -402,6 +402,8 @@ describe('ReactES6Class', function() {
402
var instance = test(<Inner name="foo" />, 'DIV', 'foo');
403
expect(() => instance.replaceState({})).toThrow();
404
expect(() => instance.isMounted()).toThrow();
405
+ expect(() => instance.setProps({name: 'bar'})).toThrow();
406
+ expect(() => instance.replaceProps({name: 'bar'})).toThrow();
407
expect(console.error.calls.count()).toBe(2);
408
expect(console.error.calls.argsFor(0)[0]).toContain(
409
'replaceState(...) is deprecated in plain JavaScript React classes'
src/isomorphic/modern/class/__tests__/ReactTypeScriptClass-test.ts
+2
@@ -489,6 +489,8 @@ describe('ReactTypeScriptClass', function() {
489
);
490
expect(() => instance.replaceState({})).toThrow();
491
expect(() => instance.isMounted()).toThrow();
492
+ expect(() => instance.setProps({ name: 'bar' })).toThrow();
493
+ expect(() => instance.replaceProps({ name: 'bar' })).toThrow();
494
expect((<any>console.error).calls.count()).toBe(2);
495
expect((<any>console.error).calls.argsFor(0)[0]).toContain(
496
'replaceState(...) is deprecated in plain JavaScript React classes'
src/renderers/shared/stack/reconciler/ReactUpdates.js
+1
-1
@@ -232,7 +232,7 @@ function enqueueUpdate(component) {
232
// Various parts of our code (such as ReactCompositeComponent's
233
// _renderValidatedComponent) assume that calls to render aren't nested;
234
// verify that that's the case. (This is called by each top-level update
235
- // function, like setState, forceUpdate, etc.; creation and
235
+ // function, like setProps, setState, forceUpdate, etc.; creation and
236
// destruction of top-level components is guarded in ReactMount.)
237
238
if (!batchingStrategy.isBatchingUpdates) {