You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can enable/disable the fetch logic directly inside the async callback. In some cases you know your API won't return anything useful.
305
+
306
+
```tsx
307
+
const asyncSearchResults =useAsync(async () => {
308
+
// It's useless to call a search API with an empty text
309
+
if (text.length===0) {
310
+
return [];
311
+
} else {
312
+
returngetSearchResultsAsync(text);
313
+
}
314
+
}, [text]);
315
+
```
316
+
302
317
#### How to have better control when things get fetched/refetched?
303
318
304
319
Sometimes you end up in situations where the function tries to fetch too often, or not often, because your dependency array changes and you don't know how to handle this.
0 commit comments