props function code example
Example 1: function component with props
import React from "react"
function Checkbox(props){
return (
<div>
<input type="checkbox" />
<label>{props.value}</label>
</div>
)
}
export default Checkbox
Example 2: props in react app
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>;
}
}
--------------------------------------------
function Welcome(props) {
return <h1>Hello, {props.name}</h1>;
}
const element = <Welcome name="Sara" />;
ReactDOM.render(
element,
document.getElementById('root')
);
Example 3: class component params in react
<input
type= "text"
value={ this.state.value || "" }
placeholder="Enter Name"
/>