Closed
Description
Suppose we have a component that accept a prop named string.
function Comp(props) {
return <div>{props.string}</div>;
}
function App() {
return <Comp string="213" />;
}
As needs change, we need to replace string prop by another named number.
function Comp(props) {
return <div>{props.number || props.string}</div>;
}
Comp.propTypes = {
number: PropTypes.number,
/**
* @deprecated use number instead
*/
string: PropTypes.string
};
Comp.defaultProps = {
string: '123',
number: 123
};
The string prop will works in a period of time, but it's better to replace it with number prop.
This rule option can be use to avoid using deprecated prop for Comp.
{
"react/forbid-component-props": [
"error", { "forbid": [{"propName": "string", "disallowedList": ["Comp"]}] }
]
}
Metadata
Metadata
Assignees
Labels
No labels