I use the code below to set default props on a React component but it doesn\'t work. In the render() method, I can see the output \"undefined props\" was printe
You can set the default props using the class name as shown below.
class Greeting extends React.Component {
render() {
return (
Hello, {this.props.name}
);
}
}
// Specifies the default values for props:
Greeting.defaultProps = {
name: 'Stranger'
};
You can use the React's recommended way from this link for more info