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>:valueordefaultValueprops onselectelement should be used instead of settingselectedprop.<textarea>:valueordefaultValueprops 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
defaultValueorvalueprops on <select> instead of settingselectedon <option>.React Warning: Use the
defaultValueorvalueprops instead of setting children on <textarea>.