Skip to content

Instantly share code, notes, and snippets.

@LuisHCK
Last active February 3, 2021 03:10
Show Gist options
  • Select an option

  • Save LuisHCK/fe0e51ea12f03335ce8219b1c0b7f5e6 to your computer and use it in GitHub Desktop.

Select an option

Save LuisHCK/fe0e51ea12f03335ce8219b1c0b7f5e6 to your computer and use it in GitHub Desktop.

Revisions

  1. LuisHCK revised this gist Feb 3, 2021. 1 changed file with 6 additions and 1 deletion.
    7 changes: 6 additions & 1 deletion react.md
    Original file line number Diff line number Diff line change
    @@ -23,8 +23,13 @@ export default function Parent() {
    import React from 'react'

    export default function ChildrenComponent(props) {

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

    return (
    <select onChange={props.onChange}>
    <select onChange={handleChange}>
    <option value="0">Cero</option>
    <option value="1">Uno</option>
    </select>
  2. LuisHCK renamed this gist Feb 3, 2021. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. LuisHCK created this gist Feb 3, 2021.
    33 changes: 33 additions & 0 deletions react
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    # Parent.js
    ```js
    import React from 'react'

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

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

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

    # Children Component

    ```js
    import React from 'react'

    export default function ChildrenComponent(props) {
    return (
    <select onChange={props.onChange}>
    <option value="0">Cero</option>
    <option value="1">Uno</option>
    </select>
    )
    }
    ```