Skip to content

Instantly share code, notes, and snippets.

@anderjs
Last active August 21, 2019 23:01
Show Gist options
  • Save anderjs/31e92423bd8169a8adb8ec9c639260cb to your computer and use it in GitHub Desktop.
Save anderjs/31e92423bd8169a8adb8ec9c639260cb to your computer and use it in GitHub Desktop.
Pass a prop
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