Skip to content

Instantly share code, notes, and snippets.

@LuisHCK
Last active February 3, 2021 03:10
Show Gist options
  • Save LuisHCK/fe0e51ea12f03335ce8219b1c0b7f5e6 to your computer and use it in GitHub Desktop.
Save LuisHCK/fe0e51ea12f03335ce8219b1c0b7f5e6 to your computer and use it in GitHub Desktop.
react.md

Parent.js

import React from 'react'

export default function Parent() {
    const [myState, setMyState] = useState()

    return (
        <div>
            <ChildComponent onChange={setMyState} />

            <p>
                {myState}
            </p>
        </div>
    )
}

Children Component

import React from 'react'

export default function ChildrenComponent(props) {

    const handleChange = (event) => {
        props.onChange(event.target.value)
    }

    return (
        <select onChange={handleChange}>
            <option value="0">Cero</option>
            <option value="1">Uno</option>
        </select>
    )
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment