react open props code example
Example 1: render props
//Render props are functions that are passed to props as values
const User = (props) => {
const [name, setName] = useState('John')
//we pass values to prop-function as args
return {props.render(name)}
}
//Then we can use this component like this:
//when using the component we receive the passed values (name) as args here
{name}
} />
Example 2: pass props in react
/* PASSING THE PROPS to the 'Greeting' component */
const expression = 'Happy';
// statement and expression are the props (ie. arguments) we are passing to Greeting component
/* USING THE PROPS in the child component */
class Greeting extends Component {
render() {
return {this.props.statement} I am feeling {this.props.expression} today!
;
}
}