Created
April 6, 2019 01:23
-
-
Save mannieschumpert/9b3c081fe628901436d6b4612117a371 to your computer and use it in GitHub Desktop.
Revisions
-
mannieschumpert created this gist
Apr 6, 2019 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,30 @@ import React, { createContext, useState } from 'react'; export const FormContext = createContext(); const Form = ({ handleSubmit, children, submitButtonText }) => { const [values, setValues] = useState({}); const setValue = ({ name, value }) => { setValues(values => ({ ...values, [name]: value, })); }; return ( <FormContext.Provider value={{ values, setValue }}> <form onSubmit={e => { e.preventDefault(); handleSubmit(values); }} > {children} <button type="submit">{submitButtonText}</button> </form> </FormContext.Provider> ); }; export default Form;