It's also called - ( lifting state up )
with the help of props send data from child to parent
// This is child
function Child(props)
{
const name="This is child";
return(
<>
<button onClick={()=>props.getData(name)} >Click Me</button>
</>
)
}
export default Child;
// This is parent
import Child from "./Child"
function Parent() {
function getName(name)
{
alert(name)
}
return (
<>
<h1>Lifting State Up</h1>
<Child getData={getName} />
</>
);
}
export default Parent;
© www.thecoderjob.com. All Rights Reserved. Designed by HTML Codex