how to pass props in react code example
Example 1: 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>;
}
}
Example 2: class component params in react
<input
type= "text"
value={ this.state.value || "" }
placeholder="Enter Name"
/>
Example 3: pass props
class Welcome extends React.Component {
render() {
return <h1>Hello, {this.props.name}</h1>;
}
}
Example 4: defining props in react
function Welcome(props) {
return <h1>Hello, {props.name}</h1>;
}
const element = <Welcome name="Sara" />;
ReactDOM.render(
element,
document.getElementById('root')
);