Browse Source

fix state update

Arnaud Vergnet 6 months ago
parent
commit
50c62dd676
1 changed files with 7 additions and 7 deletions
  1. 7
    7
      src/utils/customHooks.tsx

+ 7
- 7
src/utils/customHooks.tsx View File

@@ -78,10 +78,10 @@ export function useRequestLogic<T>(
78 78
     }
79 79
     if (canRefresh) {
80 80
       if (!response.loading) {
81
-        setResponse({
82
-          ...response,
81
+        setResponse((prevState) => ({
82
+          ...prevState,
83 83
           loading: true,
84
-        });
84
+        }));
85 85
       }
86 86
       const r = newRequest ? newRequest : request;
87 87
       r()
@@ -98,13 +98,13 @@ export function useRequestLogic<T>(
98 98
           }
99 99
         })
100 100
         .catch(() => {
101
-          setResponse({
101
+          setResponse((prevState) => ({
102 102
             loading: false,
103
-            lastRefreshDate: response.lastRefreshDate,
103
+            lastRefreshDate: prevState.lastRefreshDate,
104 104
             status: REQUEST_STATUS.CONNECTION_ERROR,
105 105
             code: undefined,
106
-            data: response.data,
107
-          });
106
+            data: prevState.data,
107
+          }));
108 108
         });
109 109
     }
110 110
   };

Loading…
Cancel
Save