Last active
August 21, 2019 23:01
-
-
Save anderjs/31e92423bd8169a8adb8ec9c639260cb to your computer and use it in GitHub Desktop.
Pass a prop
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 ChildComponent = ({ onPress }) => ( | |
<button onClick={() => onPress('Hola mundo!')}>Click me</button> | |
); | |
// Parent | |
const ParentComponent = () => { | |
const [state, setState] = React.useState(false) | |
function handleOnPress (value) { | |
// Value recibe 'Hola mundo!' | |
setState(value) | |
} | |
return ( | |
<ChildComponent onPress={handleOnPress} /> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment