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

function to overwrite global options don't update after dependency change #359

Open
joaoarieira opened this issue Jan 17, 2022 · 6 comments

Comments

@joaoarieira
Copy link

Describe the bug
I'm using a API that needs to send a dynamic value on header. But when this value changes, the function that overwrite the global options use the old value.

⚠️ Make a Codesandbox ⚠️
https://codesandbox.io/s/usefetch-use-http-todo-list-app-managed-state-forked-b6i4w?file=/src/index.js

To Reproduce
Steps to reproduce the behavior:

  1. Click on "Change dependency"
  2. See "dependency: 0" changing next to the button
  3. See console.log where the value don't change

Expected behavior
The overwite global options function must use updated values.

@alex-cory
Copy link
Collaborator

Feel free to submit a PR.

@veloware
Copy link

@joaoarieira were you ever able to get around this issue, I'm also having the same problem, thanks

@ahmadcitrusbits
Copy link

Facing the same issue

@krishnasaga
Copy link
Contributor

krishnasaga commented Dec 4, 2022

I think I resolved the issue

I modified the codesandbox https://codesandbox.io/s/usefetch-use-http-todo-list-app-managed-state-forked-q72vnx?file=/src/index.js.

Problem is the execution context of the options function and JavaScript variable reference
I believe the options function executes only once. that is at the time of mount to derive/compute the options

Plese verify and let me know if it helps

@joaoarieira @ahmadcitrusbits @veloware

@bbaduser
Copy link

bbaduser commented Dec 20, 2022

@krishnasaga hi,i can console new value by xxcurrent, but the value in post body is still old value, hope u can reply me thx!!
this is a post demo https://codesandbox.io/s/usefetch-provider-forked-hk73gu?file=/src/index.js

@krishnasaga
Copy link
Contributor

@krishnasaga hi,i can console new value by xxcurrent, but the value in post body is still old value, hope u can reply me thx!! this is a post demo https://codesandbox.io/s/usefetch-provider-forked-hk73gu?file=/src/index.js

If it is about a different issue then you need to open a new thread

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

6 participants