what is render props in react code example
Example 1: props in react
function Welcome(props) {
return <h1>Hello, {props.name}</h1>;
}
function App() {
return (
<div>
<Welcome name="Sara" /> <Welcome name="Cahal" /> <Welcome name="Edite" /> </div>
);
}
ReactDOM.render(
<App />,
document.getElementById('root')
);
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: props react
function Welcome(props) { return <h1>Hello, {props.name}</h1>;
}
const element = <Welcome name="Sara" />;ReactDOM.render(
element,
document.getElementById('root')
);