Skip to content

Instantly share code, notes, and snippets.

@trblackw
Created May 31, 2020 20:01
Show Gist options
  • Save trblackw/8b4e56bf3b583a856c815d1794596bd0 to your computer and use it in GitHub Desktop.
Save trblackw/8b4e56bf3b583a856c815d1794596bd0 to your computer and use it in GitHub Desktop.
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