Yahoo India Web Search

Search results

  1. return useSWR(dataKey, fetcher, revalidationOptions); } SWR cache is exposed since 0.2.0 version. After all, I do not recommend using SWR for this purpose. SWR built to fetch data again. If you have static data - fetch once and store in session/local storage or define your own cache. edited Feb 17, 2021 at 20:49.

  2. Mar 17, 2021 · I am using the SWR library in my NextJS project and currently i am building out a dashboard. I want to hit multiple endpoints to get different data, but I can't find any reference of making multiple

  3. Jan 23, 2021 · Keep in mind that an remote fetching comes from fetcher functions that are supplied by you, so you just configure it there. SWR hands the rest -- caching, mutation subscriptions, etc. The URL that is passed to the useSWR() hook just serves as a key that marks all data accessed that way as 'dirty' and worthy of revalidation (refetching).

  4. So just to close this off, I came back to it after working on other areas of the project and realized it was as simple as using a normal function call instead of arrow function e.g. .then(res => {feUpdate()}) don't know how I overlooked this or what was going on with testing before but it's working now.

  5. Jun 11, 2021 · data will be undefined again when you change the key (id), if it doesn't have a cache value. Remember that in SWR { data } = useSWR(key) is mentally equivalent to v = getCache(k), where fetcher (validation) just write to the cache and trigger a re-render. data is default to undefined, and isValidating means if there's an ongoing request.

  6. Apr 22, 2021 · 5. After a very long debuging I found out. fetch is getting the config object. and then makes the request to the api. then useSWR returns the response. which causes the component to re-render. the config object gets recreated. useSWR thinks argument updated and make the api request again. that's why we don't get the data.

  7. Dec 6, 2021 · 9. You can use conditional fetching in the useSWR call to prevent it from making a request. From useSWR Conditional Fetching docs: Use null or pass a function as key to conditionally fetch data. If the function throws or returns a falsy value, SWR will not start the request.

  8. Dec 2, 2021 · 2. Personally, I recommend using useSWR as it's recommended by Next.js developers; useEffect is pure react hook. The logic of useSWR is very simple, don't need to write a lot of code. In addition, you have a lot of option params as revalidateOnRender which will be very useful in development. Example from docs:

  9. Nov 4, 2021 · Line three then fails as .map only works on arrays when 'urlArr' isn't an array. This makes sense as the useSWR call takes an array for the purpose of multiple variables for the purpose of pagination. –

  10. Mar 17, 2022 · Your fetcher function is fine as is. The issue occurs because in the production build fetchAllItems.name resolves to an empty string '', meaning useSWR will not call the fetcher function as the key param is a falsy value. You have two options to solve the problem. #1 Use hardcoded string as useSWR key. Simply use a string as the key parameter ...