How to declare default props in react functional component
This is usually called a functional component, not a hook component.
For the defaultProps
you can do it like this:
const Body = ({ counter }) => {
return (
<div>
{counter}
</div>
);
}
Body.defaultProps = {
counter: 0
}
function Body({counter=0}) {
return (
<div>
body
</div>
);
}
counter now has initial value of 0