Created
May 31, 2020 20:01
-
-
Save trblackw/8b4e56bf3b583a856c815d1794596bd0 to your computer and use it in GitHub Desktop.
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
import { useImmer } from "use-immer" | |
const [users, setUsers] = useImmer([ | |
{ id: 1, name: "Bob", age: 24, emailConfirmed: false }, | |
{ id: 2, name: "Sarah", age: 30, emailConfirmed: true }, | |
{ id: 3, name: "Kevin", age: 20, emailConfirmed: false }, | |
]) | |
//when updating a user | |
setUsers(draft => { | |
draft[draft.findIndex(({ id }) => id === confirmedUserId)].emailConfirmed = true | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment