Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save pavinduLakshan/ffc1456a18eb87cf7fa98e9af869497b to your computer and use it in GitHub Desktop.
Save pavinduLakshan/ffc1456a18eb87cf7fa98e9af869497b to your computer and use it in GitHub Desktop.
import React from 'react'
const FirstComponent = ({onBtnPress}) => {
return (
// will alert "Hello Sam, from second"
<button onClick={() => onBtnPress("Sam")}></button>
)
}
const SecondComponent = ({}) => {
function sayHello(name){
alert("Hello "+ name +", from second")
}
return (
<div>
{/* Your other components here */}
<FirstComponent onBtnPress={sayHello}/>
</div>
)
}
export default SecondComponent;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment