File tree Expand file tree Collapse file tree 1 file changed +1
-17
lines changed
Expand file tree Collapse file tree 1 file changed +1
-17
lines changed Original file line number Diff line number Diff line change @@ -32,30 +32,14 @@ const BookmarkStatus: React.FC<Props> = ({
3232 mutationFn : ( ) =>
3333 bookmarkAction . toggleResourceBookmark ( { resource_id, resource_type } ) ,
3434
35- // Optimistic update before mutation
36- onMutate : async ( ) => {
37- // Cancel any ongoing fetch to prevent race conditions
38- await status . refetch ( ) ; // optional for consistency
39- const previousBookmarked = bookmarked ;
40-
41- // Optimistically toggle state
42- setBookmarked ( ( prev ) => ! prev ) ;
43-
44- return { previousBookmarked } ;
45- } ,
46-
47- // Revert if there's an error
48- onError : ( _err , _vars , context ) => {
49- setBookmarked ( context ?. previousBookmarked ?? false ) ;
50- } ,
51-
5235 // Ensure state is accurate after success
5336 onSuccess : ( data ) => {
5437 setBookmarked ( data ?. bookmarked ?? false ) ;
5538 } ,
5639 } ) ;
5740
5841 const toggle = ( ) => {
42+ setBookmarked ( ( state ) => ! state ) ;
5943 mutation . mutate ( ) ;
6044 } ;
6145
You can’t perform that action at this time.
0 commit comments