diff --git a/src/content/6/en/part6d.md b/src/content/6/en/part6d.md index 28cc0b2243c..118b64a4053 100644 --- a/src/content/6/en/part6d.md +++ b/src/content/6/en/part6d.md @@ -379,8 +379,9 @@ const App = () => { mutationFn: createNote, // highlight-start onSuccess: (newNote) => { - const notes = queryClient.getQueryData(['notes']) - queryClient.setQueryData(['notes'], notes.concat(newNote)) + queryClient.setQueryData(['notes'], (oldNotes) => + oldNotes.concat(newNote) + ) // highlight-end } }) @@ -389,7 +390,7 @@ const App = () => { } ``` -That is, in the onSuccess callback, the queryClient object first reads the existing notes state of the query and updates it by adding a new note, which is obtained as a parameter of the callback function. The value of the parameter is the value returned by the function createNote, defined in the file requests.js as follows: +That is, in the onSuccess callback, the queryClient object updates the existing notes state of the query by using the previous state and adding the new note to it. The previous state of the query is provided as a parameter to the updater function, and the new note is obtained as a parameter of the callback function. The value of the parameter is the value returned by the function createNote, defined in the file requests.js as follows: ```js export const createNote = async (newNote) => {