25
loading...
This website collects cookies to deliver better user experience
function Home(){
return(<div>
<Greeting/>
</div>)
}
Home
that renders a second function component Greeting
. Right now this is just a simple render. There is no passing of information between the two components.function Home(){
return(<div>
//passing name prop to greeting component
<Greeting name=‘Tripp’/>
</div>)
}
function Greeting(props){
return(<div>
//using prop passed down
<p>Hi there {props.name}</p>
</div>
props.name
. (If this was a Class component we would use this.props.name
. props.(name of prop being passed)
will give us access to our prop just like an argument of a function. function Home(){
//useState establishes state in a functional component
let [showSecret, setShowSecret] = useState(0)
return(<div>
<Greeting name=‘Tripp’ displaySecrete={setShowSecret}/>
{/* will show a message once state is true */}
{showSecret ? <p>Secret: You just went Against the Flow</p> : <p></p>}
</div>)
}
function Greeting(props){
return(<div>
<p>Hi there {props.name}/>
{/*clicking button will update state of the parent component and show the secret in the parent component */}
<button onClick={()=> props.displaySecrete(1)>Show Secret</button>
</div>)
}
<Greeting name=‘Tripp’ />
The Prop is called name with the value of ‘Tripp’props.name