NA +91-8727899942 thecoderjob@gmail.com

CHAPTER - 32

Send Data Child to Parent Component

It's also called - ( lifting state up )

with the help of props send data from child to parent

Here's is the Code !!

// 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;

Chapter 31

fragment in ReactJs

Previous chapter

Chapter 33

Pure component in ReactJs

Next chapter

Get In Touch

NA

thecoderjob@gmail.com

+91-8727899942

Popular Links

© www.thecoderjob.com. All Rights Reserved.               Designed by HTML Codex