Last active
September 29, 2021 13:43
-
-
Save bewarusman/1a595803a907995a9467871bf99d1c5c 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
| import { useState } from 'react'; | |
| import { useRecoilState } from "recoil"; | |
| function CreateUser() { | |
| const [, setUsers] = useRecoilState(usersState); | |
| const [name, setName] = useState(''); | |
| function handleSubmit(e) { | |
| e.preventDefault(); | |
| setUsers(users => setUsers([...users, { | |
| id: generateNewId(), | |
| name | |
| }])) | |
| } | |
| return ( | |
| <form onSubmit={handleSubmit}> | |
| <label>Name:</label> | |
| <input type="text" value={name} onChange={e => setName(e.target.value)} /> | |
| <input type="submit" value="submit" /> | |
| </form> | |
| ); | |
| } | |
| function generateNewId() { | |
| // return .... | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment