What are default props and how do you set default values today?

React JSX, components and props · Freshers and experienced

Model answer

Default values for props are normally set with default parameters in the destructuring: function Button({ size = 'md' }). The old defaultProps property on function components is deprecated in newer React, so avoid it for new code.

Defaults keep a component usable when the parent does not pass every prop.

Learn this topic

React Components and Props Explained with Examples in the course React.js Full Course: Beginner to Advanced.

Sign in to add your own answer.

More questions