Skip to content

Commit f07cb31

Browse files
authored
Merge pull request #3790 from patill/patch-1
Code update on 6d: new version of @tanstack/react-query needs a mutationFn attribute with the useMutation function call
2 parents 05a0c5b + eb840a1 commit f07cb31

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/content/6/fi/osa6d.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -259,14 +259,15 @@ import { getNotes, createNote, updateNote } from './requests' // highlight-line
259259
const App = () => {
260260
// ...
261261

262-
const updateNoteMutation = useMutation(updateNote, {
263-
onSuccess: () => {
264-
queryClient.invalidateQueries({ queryKey: ['notes'] })
262+
const updateNoteMutation = useMutation( //highligh-line
263+
{mutationFn: updateNote, // highlight-line
264+
onSuccess: () => { // highligh-line
265+
queryClient.invalidateQueries({ queryKey: ['notes'] }) // highlight-line
265266
},
266267
})
267268

268269
const toggleImportance = (note) => {
269-
updateNoteMutation.mutate({...note, important: !note.important })
270+
updateNoteMutation.mutate({...note, important: !note.important }) // highlight-line
270271
}
271272

272273
// ...
@@ -282,7 +283,8 @@ Sovelluksen tämän hetken koodi on [GitHubissa](https://github.com/fullstack-hy
282283
Sovellus toimii hyvin, ja koodikin on suhteellisen yksinkertaista. Erityisesti yllättää muistiinpanojen listan muutoksen toteuttamisen helppous. Esim. kun muutamme muistiinpanon tärkeyttä, riittää kyselyn <i>notes</i> invalidointi siihen, että sovelluksen data päivittyy:
283284

284285
```js
285-
const updateNoteMutation = useMutation(updateNote, {
286+
const updateNoteMutation = useMutation(
287+
{mutationFn: updateNote,
286288
onSuccess: () => {
287289
queryClient.invalidateQueries('notes') // highlight-line
288290
},

0 commit comments

Comments
 (0)