Skip to content

Instantly share code, notes, and snippets.

@gabrieledarrigo
Created March 23, 2022 19:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gabrieledarrigo/d437b07923017797357ce254e729be96 to your computer and use it in GitHub Desktop.
Save gabrieledarrigo/d437b07923017797357ce254e729be96 to your computer and use it in GitHub Desktop.
Evil Hook
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