Deprecated prop for a React DOM element should not be used
- REACT_DEPRECATED_DOM_ELEMENT_PROP
- Code Quality
- Medium
- react
This rule applies when deprecated prop for a React DOM element is used.
Deprecated props for a React DOM element and their replacement are as the following:
textarea
element:value
ordefaultValue
props should be used instead of setting child node.option
element:value
ordefaultValue
props onselect
element should be used instead of settingselected
prop.input
element:value
withonChange
prop should be used instead of setting deprecatedcheckedLink
prop.
React outputs a warning message for all above cases, and deprecated props may not work in a future version of React.
Noncompliant Code Example
View with compliant examples side by sideimport React from 'react';
export class Example1 extends React.Component {
render() {
return <textarea>Hi</textarea>; // REACT_DEPRECATED_DOM_ELEMENT_PROP alarm because child node is set on 'textarea' element.
}
}
export class Example2 extends React.Component {
render() {
return (
<select>
<option value="hi">Hi</option>
<option selected value="hello">Hello</option> {/* REACT_DEPRECATED_DOM_ELEMENT_PROP alarm because 'selected' prop is set on 'option' element. */}
</select>
);
}
}
import createReactClass from 'create-react-class';
import LinkedStateMixin from 'react-addons-linked-state-mixin';
export var Example3 = createReactClass({
mixins: [LinkedStateMixin],
getInitialState: function () {
return { check: false };
},
render: function () {
return <input type="checkbox" checkedLink={this.linkState('check')} />; // REACT_DEPRECATED_DOM_ELEMENT_PROP alarm because 'checkedLink' prop is set on 'input' element.
}
});
Compliant Code Example
View with noncompliant examples side by sideimport React from 'react';
export class Example1 extends React.Component {
constructor(props) {
super(props);
this.state = { value: 'Hi' };
this.handleChange = this.handleChange.bind(this);
}
handleChange(e) {
this.setState({ value: e.target.value });
}
render() {
return <textarea value={this.state.value} onChange={this.handleChange} />;
}
}
export class Example2 extends React.Component {
constructor(props) {
super(props);
this.state = { value: 'hello' };
this.handleChange = this.handleChange.bind(this);
}
handleChange(e) {
this.setState({ value: e.target.value });
}
render() {
return (
<select value={this.state.value} onChange={this.handleChange}>
<option value="hi">Hi</option>
<option value="hello">Hello</option>
</select>
);
}
}
import createReactClass from 'create-react-class';
export var Example3 = createReactClass({
getInitialState: function () {
return { check: false };
},
handleChange: function (e) {
this.setState({ check: e.target.value });
},
render: function () {
return <input type="checkbox" value={this.state.check} defaultChecked={this.state.check} onChange={this.handleChange} />;
}
});
Version
This rule was introduced in DeepScan 1.6.0-beta.
See
React Warning: Use the
defaultValue
orvalue
props on <select> instead of settingselected
on <option>.React Warning: Use the
defaultValue
orvalue
props instead of setting children on <textarea>.React Warning:
checkedLink
prop oninput
is deprecated; setvalue
andonChange
instead.