Reputation: 13956
Can anyone tell me the difference between these 2 eslint rules.
react/prop-types vs react/require-default-props
As far as my understanding goes, they both do the same things.
Upvotes: 0
Views: 1347
Reputation: 6253
They do not do the same thing.
The first one is an eslint-rule to check that used props are also defined in prop-types. The second one is a rule for enforcing the props that are not required are set in defaultProps
Upvotes: 1
Reputation: 334
react/prop-types checks only if there are prop-types set.
react/require-default-props enforces the developer to set a default value for each prop.
const HelloWorld = ({ name }) => (
<h1>Hello, {name}!</h1>
);
// eslint react/prop-types will complain if you leave out this block
HelloWorld.propTypes = {
name: PropTypes.string
};
// eslint react/require-default-props checks for the following block
HelloWorld.defaultProps = {
name: 'john'
};
ReactDOM.render(<HelloWorld />, document.getElementById('app'));
Upvotes: 2