What are default props?

Posted by Andre Scott | Updated on

What are default props?

The defaultProps are defined as a property on the component class to set the default props for the class. This is used for undefined props, but not for null props.

For example, let us create color default prop for the button component,

If props.color is not provided then it will set the default value to ‘red’. i.e, Whenever you try to access the color prop it uses default value


If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.

Related Questions & Answers