@@ -47,7 +47,7 @@ export const PostPage = () => {
4747 queryKey : [ "users" , post ?. userId ] ,
4848 queryFn : async ( ) => {
4949 const response = await fetch (
50- `http://localhost:3333/users/${ post ?. userId } ` ,
50+ `http://localhost:3333/users/${ post ?. userId } `
5151 ) ;
5252 return response . json ( ) as Promise < IUser > ;
5353 } ,
@@ -64,7 +64,7 @@ export const PostPage = () => {
6464 queryKey : [ "posts" , postId , "comments" ] ,
6565 queryFn : async ( ) => {
6666 const response = await fetch (
67- `http://localhost:3333/posts/${ postId } /comments` ,
67+ `http://localhost:3333/posts/${ postId } /comments`
6868 ) ;
6969 return response . json ( ) as Promise < IComment [ ] > ;
7070 } ,
@@ -82,7 +82,7 @@ export const PostPage = () => {
8282 `http://localhost:3333/comments/${ commentId } ` ,
8383 {
8484 method : "DELETE" ,
85- } ,
85+ }
8686 ) ;
8787 return response . json ( ) as Promise < IComment > ;
8888 } ,
@@ -91,7 +91,7 @@ export const PostPage = () => {
9191 onError : ( err , commentId ) => {
9292 console . error (
9393 `Error deleting comment ${ commentId } . Rolling UI back` ,
94- err ,
94+ err
9595 ) ;
9696 alert ( "Error deleting comment" ) ;
9797 } ,
@@ -133,7 +133,7 @@ export const PostPage = () => {
133133 // Optimistically update to the new value
134134 queryClient . setQueryData (
135135 [ "posts" , postId , "comments" ] ,
136- ( oldComments : any ) => [ ...oldComments , newComment ] ,
136+ ( oldComments : any ) => [ ...oldComments , newComment ]
137137 ) ;
138138
139139 // Return a context object with the snapshot value
@@ -144,7 +144,7 @@ export const PostPage = () => {
144144 onError : ( err , _newComment , context ) => {
145145 queryClient . setQueryData (
146146 [ "posts" , postId , "comments" ] ,
147- context ?. previousComments ,
147+ context ?. previousComments
148148 ) ;
149149 console . error ( "Error posting comment. Rolling UI back" , err ) ;
150150 } ,
@@ -153,7 +153,9 @@ export const PostPage = () => {
153153 } ,
154154 // Always refetch after error or success:
155155 onSettled : ( ) => {
156- queryClient . invalidateQueries ( { queryKey : [ "comments" ] } ) ;
156+ queryClient . invalidateQueries ( {
157+ queryKey : [ "posts" , postId , "comments" ] ,
158+ } ) ;
157159 } ,
158160 } ) ;
159161
0 commit comments