react render component with props code example
Example 1: class app extends component syntax
class Welcome extends React.Component {
render() {
return <h1>Hello, {this.props.name}</h1>;
}
}
Example 2: render props
const User = (props) => {
const [name, setName] = useState('John')
return <div>{props.render(name)}</div>
}
<div>
<User render={(name) => <div>{name}</div>} />
</div>
Example 3: pass props in react
const expression = 'Happy';
<Greeting statement='Hello' expression={expression}/>
class Greeting extends Component {
render() {
return <h1>{this.props.statement} I am feeling {this.props.expression} today!</h1>;
}
}