You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: apps/svelte.dev/content/tutorial/03-sveltekit/07-api-routes/02-post-handlers/+assets/app-b/src/routes/+page.svelte
Copy file name to clipboardExpand all lines: apps/svelte.dev/content/tutorial/03-sveltekit/07-api-routes/02-post-handlers/index.md
+5-3Lines changed: 5 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -74,14 +74,16 @@ We're returning a response with a [201 Created](https://http.dog/201) status and
74
74
75
75
+++ const { id } = await response.json();
76
76
77
-
data.todos = [...data.todos, {
77
+
const todos = [...data.todos, {
78
78
id,
79
79
description
80
-
}];+++
80
+
}];
81
+
82
+
data = { ...data, todos };+++
81
83
82
84
input.value = '';
83
85
}}
84
86
/>
85
87
```
86
88
87
-
> [!NOTE] You should only mutate`data` in such a way that you'd get the same result by reloading the page.
89
+
> [!NOTE] You should only update`data` in such a way that you'd get the same result by reloading the page. The `data` prop is not _deeply_ reactive, so you need to replace it — mutations like `data.todos = todos` will not cause a re-render.
0 commit comments