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
Post a Comment