Last active
October 6, 2020 08:20
-
-
Save phobon/544e8e69bcd82fc28137c8a4f5113e83 to your computer and use it in GitHub Desktop.
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 characters
const dataAtom = atom({}); | |
const Form = ({ code, name, categories, dimensions, setData, ...props }) => { | |
const [code, setCode] = useState(() => code); | |
const [name, setName] = useState(() => name); | |
const [categories, setCategories] = useState(() => categories); | |
const [dimensions, setDimensions] = useState(() => dimensions); | |
const updateData = e => setData({ | |
code, | |
name, | |
categories, | |
dimensions, | |
}); | |
return ( | |
<form onSubmit={updateData} {...props}> | |
...your controls... | |
</form> | |
); | |
}; | |
const App = () => { | |
const [data, setData] = useAtom(dataAtom); | |
return ( | |
<Form {...data} setData={setData} /> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment