Skip to content

Instantly share code, notes, and snippets.

@jeanbauer
Created December 16, 2018 01:15
Show Gist options
  • Save jeanbauer/00c06ddfa44a199dd9aa018c1f4775f2 to your computer and use it in GitHub Desktop.
Save jeanbauer/00c06ddfa44a199dd9aa018c1f4775f2 to your computer and use it in GitHub Desktop.

Revisions

  1. jeanbauer created this gist Dec 16, 2018.
    26 changes: 26 additions & 0 deletions form.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    import { useState } from 'react'

    const Form = () => {
    const name = useFormInput('Name')

    return (
    <>
    <input {...name} />
    </>
    )
    }

    function useFormInput(initialValue) {
    const [value, setValue] = useState(initialValue)

    function handleChange(e) {
    setValue(e.target.value)
    }

    return {
    value,
    onChange: handleChange
    }
    }

    export default Form