use-http icon indicating copy to clipboard operation
use-http copied to clipboard

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

Open joaoarieira opened this issue 4 years ago • 6 comments

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.

joaoarieira avatar Jan 17 '22 17:01 joaoarieira

Feel free to submit a PR.

iamthesiz avatar Jan 25 '22 08:01 iamthesiz

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

veloware avatar Jun 21 '22 09:06 veloware

Facing the same issue

ahmadcitrusbits avatar Oct 14 '22 07:10 ahmadcitrusbits

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

krishnasaga avatar Dec 04 '22 13:12 krishnasaga

@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

bbaduser avatar Dec 20 '22 04:12 bbaduser

@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

krishnasaga avatar Dec 21 '22 18:12 krishnasaga