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 replacements are as the following:
<option>
:value
ordefaultValue
props onselect
element should be used instead of settingselected
prop.<textarea>
:value
ordefaultValue
props should be used instead of setting child node.
React outputs warning messages for the above cases, and deprecated props may not work in future versions of React.
Noncompliant Code Example
View with compliant examples side by sideimport { createRoot } from 'react-dom/client';
const root = createRoot(document.getElementById('root'));
root.render(
<>
{/* Example 1 */}
<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>'. */}
</select>
{/* Example 2 */}
<textarea>Hi</textarea> {/* REACT_DEPRECATED_DOM_ELEMENT_PROP alarm because child node is set on '<textarea>' */}
</>
);
Compliant Code Example
View with noncompliant examples side by sideimport { createRoot } from 'react-dom/client';
const root = createRoot(document.getElementById('root'));
root.render(
<>
{/* Example 1 */}
<select defaultValue="hello">
<option value="hi">Hi</option>
<option value="hello">Hello</option>
</select>
{/* Example 2 */}
<textarea defaultValue="Hi" />
</>
);
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>.