ReACT -Props
ReACT-Props
One Props
function Hello(props) {
return <div>Hello, {props.who}!</div>;
}
const user = <Hello who=”Earth” />;
ReactDOM.render(
user,
document.getElementById(‘root’)
);
2 Props
function Hello(props)
{
return <div>Hello, {props.who2}!</div>;
}
const user = <Hello who=”Earth” who2=”Luna” />;
ReactDOM.render(
user,
document.getElementById(‘root’));
2 Props-2
function Hello(props) {
return <div>Hello, {props.who}, {props.who2}!</div>;
}
const user = <Hello who=”Earth” who2=”Luna” />;
ReactDOM.render(
user,
document.getElementById(‘root’)
);
Class Based Approach
We use “this”
import { Component } from ‘react’;
class Hello extends Component {
render()
{
return <div>Hello, {this.props.who}!</div>;
}
}
const user = <Hello who=”Earth” />;
ReactDOM.render(
user,
document.getElementById(‘root’)
);
Note: Thank you https://dmitripavlutin.com/react-props/ for clarification this concept.