Skip to main content

Default Props

In react js we can set default props like this

export default function App({title: "example title"}){
return <p>{title}</p>
}

It is normally, but there is another way to set default props. How is that? For set default props we can set using defaultProps object like this

export default function App({ title }) {
return <p>{title}</p>;
}

// set props like below
App.defaultProps = {
title: "example title",
};

With this we can to set default props and our code is clean and readable