1
I’m a beginner in React, and I’m trying to set a default value for a prop if it’s not passed, but it’s not working.
Title.js
import React, { Component } from 'react';
export default class Title extends Component {
render() {
return (
<div>
<h1>Hello, {this.props.name }</h1>
</div>
);
}
}
Title.defaultProps = {
name:'Janio Carvalho Jr'
}
App.js
function App() {
return (
<div className='container'>
<Title name />
</div>
);
};