Created
March 23, 2022 19:09
-
-
Save gabrieledarrigo/d437b07923017797357ce254e729be96 to your computer and use it in GitHub Desktop.
Evil Hook
This file contains 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
function App ({ id, values }) { | |
const [user, setUser] = useState(null); | |
const payload = { | |
id, | |
...values, | |
// compute some stuff | |
}; | |
useEffect(() => { | |
fetch(`/users/${params.id}`, { | |
method: 'PUT', | |
body: JSON.stringify(payload) | |
}) | |
.then(response => response.json) | |
.then(user => { setUser(user) }); | |
}, [payload]); | |
return ( | |
<div> | |
... | |
</div> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment