GithubHelp home page GithubHelp logo

Comments (8)

ConsoleTVs avatar ConsoleTVs commented on May 13, 2024

Can I know more about what service.playerList does under the hood?

from sswr.

frederikhors avatar frederikhors commented on May 13, 2024

Can I know more about what service.playerList does under the hood?

In the REPL for this issue I used a simple fetch with the same issue: https://svelte.dev/repl/40782b4783244075b8c58cffbcf9acd4?version=3.42.1.

My service is similar.

from sswr.

frederikhors avatar frederikhors commented on May 13, 2024

THIS IS HUGE and prevent me from using sswr today.

from sswr.

ConsoleTVs avatar ConsoleTVs commented on May 13, 2024

I'm going to explore this after work. Thanks for the report.

from sswr.

Terrahop avatar Terrahop commented on May 13, 2024

Having the same issue here with trying to get pagination to work.

Given the following code in a svelte component:

  /** Item position to start at */
  let offset = 0
  /** Number of items to get */
  let first = 10

  $: ({ data: pageData } = useSWR(() => 'pageItems', {
    fetcher: () => query('someItemList', { first, offset })
  }))

  $: console.log('page data', $pageData)

pageData is initially populated with data however when I update offset via a button press (offset += first), pageData becomes undefined and then no longer updates either on further changes to offset.

The same behaviour happens when not using a custom fetcher:

{...}
  $: ({ data: pageData } = useSWR(() => `api/someItemList?first=${first}&offset=${offset}`))
{...}

from sswr.

benbender avatar benbender commented on May 13, 2024

@Terrahop You are simply rerunning useSWR reactivly with different parameters. Therefor data is initialized as undefined at the beginning of the new request as per docs. See:

data: Writable<D | undefined>: Stores the data of the HTTP response after the fetcher has processed it or undefined in case the HTTP request hasn't finished or there was an error.

So imho this is expected behaviour.

The solution to this is either:

  • save the old data in an intermediate variable until new data arrives (outside of useSWR())
  • extend the api of useSWR with something like keepData: boolean.

from sswr.

Terrahop avatar Terrahop commented on May 13, 2024

Ah got it thanks for clearing that up, I'll take a look at extending useSWR then.

from sswr.

akiarostami avatar akiarostami commented on May 13, 2024

I'm facing this issue as well, which is preventing me from using useSWR, unfortunately.

from sswr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.