Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New requests not fired when dependency array changes #156

Closed
peterssonjesper opened this issue Dec 10, 2019 · 4 comments
Closed

New requests not fired when dependency array changes #156

peterssonjesper opened this issue Dec 10, 2019 · 4 comments

Comments

@peterssonjesper
Copy link

Hi,

Thanks for the excellent work on this library!

I ran into some issues today, and I'm not sure that this is because of some bug, or simply because I have misunderstood how the API is supposed to work. The case has to do with firing new requests as entries in the dependency array changes.

For instance, I was expecting the following to fire a new request whenever id changes:

const stuff = useFetch(`/user${id}.json`, [id]);

What happens is that the request is initially fired on mount, but as id changes, nothing happens.

I've probably misunderstood how this is supposed to work, but if not then this might be some bug that I'm hitting. I have a complete example reproducing it available here: https://codesandbox.io/s/usefetch-dependency-array-slsb9?fontsize=14&hidenavigation=1&theme=dark

Thanks,
Jesper

@alex-cory
Copy link
Collaborator

alex-cory commented Dec 10, 2019

One sec, taking a look now.

@alex-cory
Copy link
Collaborator

alex-cory commented Dec 10, 2019

It's working. Take a look at the network tab, and filter by the word user. You can see as I click it makes a call for user1, then user2, and so on. Here's a screenshot
image
image

@alex-cory
Copy link
Collaborator

Make sure you're using the latest version (currently 0.2.4), and if something doesn't seem to be quite working in codesandbox, always click the refresh ⟲ button on the package in the dependencies on the left. Sometimes codesandbox can be buggy and load an old version of the npm package. Here's a screenshot for reference.
image

Going to close this for now, but if the issue persists, just comment again and I'll reopen the issue. 🙂

@peterssonjesper
Copy link
Author

Omg, you are totally right. I bumped to 0.2.4 (I was on 0.2.1 locally, not sure about what version codesandbox was using) and now it works like a charm!

Big thanks for the quick response!

Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants