Send Data Child to Parent Component - React Js

 App.js:


import React from "react";

import './App.css'
import { Student } from "./Components/Student";

function App()
{
  function alertFunc(data)
  {
    alert(data)
  }
  const name="Krishan Dev"
  return(
    <div className="App">
   <Student data={name} alert1={alertFunc}/>
   
    </div>
  )
}

export default App;


----------------------------

Student.js

import React from 'react'

export const Student = (props) => {

  const data="Bhavesh"
  return (
    <div>
      <h6>{props.data}</h6>
      <button onClick={props.alert1(data)}>Click Me</button>
    </div>
  )
}





Comments

Popular posts from this blog

Hide , Show and Toggle in ReactJs

Importance Of Web Content In SEO.