Created
July 17, 2020 16:56
-
-
Save pavinduLakshan/ffc1456a18eb87cf7fa98e9af869497b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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