Skip to content

Commit 50c7b17

Browse files
committed
Merge pull request #5570 from jimfb/remove-setprops-replaceprops
Remove setProps and replaceProps.
2 parents 0be7786 + fbf81a8 commit 50c7b17

File tree

8 files changed

+20
-214
lines changed

8 files changed

+20
-214
lines changed

src/isomorphic/classic/class/ReactClass.js

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,6 @@ var SpecPolicy = keyMirror({
5454

5555
var injectedMixins = [];
5656

57-
var warnedSetProps = false;
58-
function warnSetProps() {
59-
if (!warnedSetProps) {
60-
warnedSetProps = true;
61-
warning(
62-
false,
63-
'setProps(...) and replaceProps(...) are deprecated. ' +
64-
'Instead, call render again at the top level.'
65-
);
66-
}
67-
}
68-
6957
/**
7058
* Composite components are higher-level components that compose other composite
7159
* or native components.
@@ -737,44 +725,6 @@ var ReactClassMixin = {
737725
isMounted: function() {
738726
return this.updater.isMounted(this);
739727
},
740-
741-
/**
742-
* Sets a subset of the props.
743-
*
744-
* @param {object} partialProps Subset of the next props.
745-
* @param {?function} callback Called after props are updated.
746-
* @final
747-
* @public
748-
* @deprecated
749-
*/
750-
setProps: function(partialProps, callback) {
751-
if (__DEV__) {
752-
warnSetProps();
753-
}
754-
this.updater.enqueueSetProps(this, partialProps);
755-
if (callback) {
756-
this.updater.enqueueCallback(this, callback);
757-
}
758-
},
759-
760-
/**
761-
* Replace all the props.
762-
*
763-
* @param {object} newProps Subset of the next props.
764-
* @param {?function} callback Called after props are updated.
765-
* @final
766-
* @public
767-
* @deprecated
768-
*/
769-
replaceProps: function(newProps, callback) {
770-
if (__DEV__) {
771-
warnSetProps();
772-
}
773-
this.updater.enqueueReplaceProps(this, newProps);
774-
if (callback) {
775-
this.updater.enqueueCallback(this, callback);
776-
}
777-
},
778728
};
779729

780730
var ReactClassComponent = function() {};

src/isomorphic/modern/class/ReactComponent.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,19 +115,11 @@ if (__DEV__) {
115115
'Instead, make sure to clean up subscriptions and pending requests in ' +
116116
'componentWillUnmount to prevent memory leaks.',
117117
],
118-
replaceProps: [
119-
'replaceProps',
120-
'Instead, call render again at the top level.',
121-
],
122118
replaceState: [
123119
'replaceState',
124120
'Refactor your code to use setState instead (see ' +
125121
'https://github.com/facebook/react/issues/3236).',
126122
],
127-
setProps: [
128-
'setProps',
129-
'Instead, call render again at the top level.',
130-
],
131123
};
132124
var defineDeprecationWarning = function(methodName, info) {
133125
if (canDefineProperty) {

src/isomorphic/modern/class/ReactNoopUpdateQueue.js

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -98,29 +98,6 @@ var ReactNoopUpdateQueue = {
9898
enqueueSetState: function(publicInstance, partialState) {
9999
warnTDZ(publicInstance, 'setState');
100100
},
101-
102-
/**
103-
* Sets a subset of the props.
104-
*
105-
* @param {ReactClass} publicInstance The instance that should rerender.
106-
* @param {object} partialProps Subset of the next props.
107-
* @internal
108-
*/
109-
enqueueSetProps: function(publicInstance, partialProps) {
110-
warnTDZ(publicInstance, 'setProps');
111-
},
112-
113-
/**
114-
* Replaces all of the props.
115-
*
116-
* @param {ReactClass} publicInstance The instance that should rerender.
117-
* @param {object} props New props.
118-
* @internal
119-
*/
120-
enqueueReplaceProps: function(publicInstance, props) {
121-
warnTDZ(publicInstance, 'replaceProps');
122-
},
123-
124101
};
125102

126103
module.exports = ReactNoopUpdateQueue;

src/isomorphic/modern/class/__tests__/ReactCoffeeScriptClass-test.coffee

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ describe 'ReactCoffeeScriptClass', ->
350350
expect(-> instance.isMounted()).toThrow()
351351
expect(-> instance.setProps name: 'bar').toThrow()
352352
expect(-> instance.replaceProps name: 'bar').toThrow()
353-
expect(console.error.calls.length).toBe 5
353+
expect(console.error.calls.length).toBe 3
354354
expect(console.error.argsForCall[0][0]).toContain(
355355
'getDOMNode(...) is deprecated in plain JavaScript React classes'
356356
)
@@ -360,12 +360,6 @@ describe 'ReactCoffeeScriptClass', ->
360360
expect(console.error.argsForCall[2][0]).toContain(
361361
'isMounted(...) is deprecated in plain JavaScript React classes'
362362
)
363-
expect(console.error.argsForCall[3][0]).toContain(
364-
'setProps(...) is deprecated in plain JavaScript React classes'
365-
)
366-
expect(console.error.argsForCall[4][0]).toContain(
367-
'replaceProps(...) is deprecated in plain JavaScript React classes'
368-
)
369363

370364
it 'supports this.context passed via getChildContext', ->
371365
class Bar extends React.Component

src/isomorphic/modern/class/__tests__/ReactES6Class-test.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ describe('ReactES6Class', function() {
407407
expect(() => instance.isMounted()).toThrow();
408408
expect(() => instance.setProps({name: 'bar'})).toThrow();
409409
expect(() => instance.replaceProps({name: 'bar'})).toThrow();
410-
expect(console.error.calls.length).toBe(5);
410+
expect(console.error.calls.length).toBe(3);
411411
expect(console.error.argsForCall[0][0]).toContain(
412412
'getDOMNode(...) is deprecated in plain JavaScript React classes. ' +
413413
'Use ReactDOM.findDOMNode(component) instead.'
@@ -418,12 +418,6 @@ describe('ReactES6Class', function() {
418418
expect(console.error.argsForCall[2][0]).toContain(
419419
'isMounted(...) is deprecated in plain JavaScript React classes'
420420
);
421-
expect(console.error.argsForCall[3][0]).toContain(
422-
'setProps(...) is deprecated in plain JavaScript React classes'
423-
);
424-
expect(console.error.argsForCall[4][0]).toContain(
425-
'replaceProps(...) is deprecated in plain JavaScript React classes'
426-
);
427421
});
428422

429423
it('supports this.context passed via getChildContext', function() {

src/isomorphic/modern/class/__tests__/ReactTypeScriptClass-test.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ describe('ReactTypeScriptClass', function() {
491491
expect(() => instance.isMounted()).toThrow();
492492
expect(() => instance.setProps({ name: 'bar' })).toThrow();
493493
expect(() => instance.replaceProps({ name: 'bar' })).toThrow();
494-
expect((<any>console.error).argsForCall.length).toBe(5);
494+
expect((<any>console.error).argsForCall.length).toBe(3);
495495
expect((<any>console.error).argsForCall[0][0]).toContain(
496496
'getDOMNode(...) is deprecated in plain JavaScript React classes'
497497
);
@@ -501,12 +501,6 @@ describe('ReactTypeScriptClass', function() {
501501
expect((<any>console.error).argsForCall[2][0]).toContain(
502502
'isMounted(...) is deprecated in plain JavaScript React classes'
503503
);
504-
expect((<any>console.error).argsForCall[3][0]).toContain(
505-
'setProps(...) is deprecated in plain JavaScript React classes'
506-
);
507-
expect((<any>console.error).argsForCall[4][0]).toContain(
508-
'replaceProps(...) is deprecated in plain JavaScript React classes'
509-
);
510504
});
511505

512506
it('supports this.context passed via getChildContext', function() {

src/renderers/shared/reconciler/__tests__/ReactComponentLifeCycle-test.js

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -444,47 +444,6 @@ describe('ReactComponentLifeCycle', function() {
444444
expect(instance.state).toEqual(POST_WILL_UNMOUNT_STATE);
445445
});
446446

447-
it('should throw when calling setProps() on an owned component', function() {
448-
/**
449-
* calls setProps in an componentDidMount.
450-
*/
451-
var Inner = React.createClass({
452-
render: function() {
453-
return <div />;
454-
},
455-
});
456-
var PropsUpdaterInOnDOMReady = React.createClass({
457-
componentDidMount: function() {
458-
this.refs.theSimpleComponent.setProps({
459-
className: this.props.valueToUseInOnDOMReady,
460-
});
461-
},
462-
render: function() {
463-
return (
464-
<Inner
465-
className={this.props.valueToUseInitially}
466-
ref="theSimpleComponent"
467-
/>
468-
);
469-
},
470-
});
471-
var instance =
472-
<PropsUpdaterInOnDOMReady
473-
valueToUseInitially="hello"
474-
valueToUseInOnDOMReady="goodbye"
475-
/>;
476-
spyOn(console, 'error');
477-
expect(function() {
478-
instance = ReactTestUtils.renderIntoDocument(instance);
479-
}).toThrow(
480-
'setProps(...): You called `setProps` on a component with a parent. ' +
481-
'This is an anti-pattern since props will get reactively updated ' +
482-
'when rendered. Instead, change the owner\'s `render` method to pass ' +
483-
'the correct value as props to the component where it is created.'
484-
);
485-
expect(console.error.calls.length).toBe(1); // setProps deprecated
486-
});
487-
488447
it('should not throw when updating an auxiliary component', function() {
489448
var Tooltip = React.createClass({
490449
render: function() {

src/renderers/shared/reconciler/__tests__/ReactCompositeComponent-test.js

Lines changed: 17 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,23 @@ describe('ReactCompositeComponent', function() {
137137
});
138138

139139
it('should not cache old DOM nodes when switching constructors', function() {
140-
var instance = <ChildUpdates renderAnchor={true} anchorClassOn={false}/>;
141-
instance = ReactTestUtils.renderIntoDocument(instance);
142-
instance.setProps({anchorClassOn: true}); // Warm any cache
143-
instance.setProps({renderAnchor: false}); // Clear out the anchor
144-
// rerender
145-
instance.setProps({renderAnchor: true, anchorClassOn: false});
140+
var container = document.createElement('div');
141+
var instance = ReactDOM.render(
142+
<ChildUpdates renderAnchor={true} anchorClassOn={false}/>,
143+
container
144+
);
145+
ReactDOM.render( // Warm any cache
146+
<ChildUpdates renderAnchor={true} anchorClassOn={true}/>,
147+
container
148+
);
149+
ReactDOM.render( // Clear out the anchor
150+
<ChildUpdates renderAnchor={false} anchorClassOn={true}/>,
151+
container
152+
);
153+
ReactDOM.render( // rerender
154+
<ChildUpdates renderAnchor={true} anchorClassOn={false}/>,
155+
container
156+
);
146157
expect(instance.getAnchor().className).toBe('');
147158
});
148159

@@ -398,71 +409,6 @@ describe('ReactCompositeComponent', function() {
398409
expect(instance2.state.value).toBe(1);
399410
});
400411

401-
it('should not allow `setProps` on unmounted components', function() {
402-
var container = document.createElement('div');
403-
document.body.appendChild(container);
404-
405-
var Component = React.createClass({
406-
render: function() {
407-
return <div />;
408-
},
409-
});
410-
411-
var instance = <Component />;
412-
expect(instance.setProps).not.toBeDefined();
413-
414-
instance = ReactDOM.render(instance, container);
415-
expect(function() {
416-
instance.setProps({value: 1});
417-
}).not.toThrow();
418-
expect(console.error.calls.length).toBe(1); // setProps deprecated
419-
420-
ReactDOM.unmountComponentAtNode(container);
421-
expect(function() {
422-
instance.setProps({value: 2});
423-
}).not.toThrow();
424-
425-
expect(console.error.calls.length).toBe(2);
426-
expect(console.error.argsForCall[1][0]).toBe(
427-
'Warning: setProps(...): Can only update a mounted or ' +
428-
'mounting component. This usually means you called setProps() on an ' +
429-
'unmounted component. This is a no-op. Please check the code for the ' +
430-
'Component component.'
431-
);
432-
});
433-
434-
it('should only allow `setProps` on top-level components', function() {
435-
var container = document.createElement('div');
436-
document.body.appendChild(container);
437-
438-
var innerInstance;
439-
440-
var Inner = React.createClass({
441-
render: function() {
442-
return <div />;
443-
},
444-
});
445-
var Component = React.createClass({
446-
render: function() {
447-
return <div><Inner ref="inner" /></div>;
448-
},
449-
componentDidMount: function() {
450-
innerInstance = this.refs.inner;
451-
},
452-
});
453-
ReactDOM.render(<Component />, container);
454-
455-
expect(innerInstance).not.toBe(undefined);
456-
expect(function() {
457-
innerInstance.setProps({value: 1});
458-
}).toThrow(
459-
'setProps(...): You called `setProps` on a component with a parent. ' +
460-
'This is an anti-pattern since props will get reactively updated when ' +
461-
'rendered. Instead, change the owner\'s `render` method to pass the ' +
462-
'correct value as props to the component where it is created.'
463-
);
464-
});
465-
466412
it('should cleanup even if render() fatals', function() {
467413
var BadComponent = React.createClass({
468414
render: function() {

0 commit comments

Comments
 (0)