Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update update-patterns.md to resetting/clearing #1082

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion website/docs/update-patterns.md
Expand Up @@ -26,7 +26,7 @@ const addedTodosObj = produce(todosObj, draft => {
draft["id3"] = {done: false, body: "Buy bananas"}
})

// delete
// delete single property
const deletedTodosObj = produce(todosObj, draft => {
delete draft["id1"]
})
Expand All @@ -35,6 +35,11 @@ const deletedTodosObj = produce(todosObj, draft => {
const updatedTodosObj = produce(todosObj, draft => {
draft["id1"].done = true
})

// reset/clear/empty
const emptyTodo = produce(todosObj, () => {
return {};
})
```

### Array mutations
Expand Down Expand Up @@ -102,6 +107,11 @@ const updatedTodosArray = produce(todosArray, draft => {
// level produce is still pretty useful)
return draft.filter(todo => todo.done)
})

// reset/clear/empty
const emptyTodo = produce(todosArray, () => {
return [];
})
```

### Nested data structures
Expand Down