question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`useFetch` does not refresh when a params object is used

See original GitHub issue

Environment

Linux

Reproduction

Go to: https://stackblitz.com/edit/github-mt2nv8?file=app.vue

Try to increase the page by pressing the respective button. The same request is performed with each button press.

As described in the sandbox, using the _start param as part of the url works properly.

Describe the bug

The refresh function of the useFetch composable does not properly refresh requests that depend on params object instead of params in the url itself.

Additional context

No response

Logs

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
danielroecommented, May 13, 2022

Yes. You should instead use it in the URL directly as I have done above, as the params are ‘frozen’ in time when the setup function runs. (This is not unique to Nuxt, but is a caveat of Vue reactivity.)

0reactions
shtse8commented, Jun 28, 2022

Yes. You should instead use it in the URL directly as I have done above, as the params are ‘frozen’ in time when the setup function runs. (This is not unique to Nuxt, but is a caveat of Vue reactivity.)

when using it in url, the response type cannot be solved in typescript. type will become unknown. I suggest we can have something like

const next = ref('')
const { data } = await useFetch('/api/list', {
    params: {
      next: () => next.value,
    },
  })
Read more comments on GitHub >

github_iconTop Results From Across the Web

useFetch refresh not working when params change #5653
This is how Vue reactivity works - the value is frozen in time when you call useFetch : see #4970. If you want...
Read more >
useFetch of Nuxt 3 sends same request during refresh ...
I've created a pull request on nuxt/framework to have it reflected in the documentation. Please see a full explanation below: Using the query ......
Read more >
useFetch
It's an isomorphic fetch hook. That means it works with SSR (server side rendering). A note on the documentation below. Many of these...
Read more >
Fetching Data and Updating State with React Hooks
The guide detailed how to do this with the componentDidMount() lifecycle method that every React class component provides. Many components, ...
Read more >
useFetch
The useFetch function can be used by simply providing a url. The url can be either a string or a ref . The...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found