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

Deleting a global option persists for all instances #250

Closed
mercyaj opened this issue Apr 20, 2020 · 5 comments · Fixed by #258
Closed

Deleting a global option persists for all instances #250

mercyaj opened this issue Apr 20, 2020 · 5 comments · Fixed by #258

Comments

@mercyaj
Copy link
Contributor

mercyaj commented Apr 20, 2020

Possibly related to #135

Describe the bug
When deleting/overwriting a global option in one instance of useFetch, the global options are then permanently modified across all instances.

Following the example in the README:

 // let's say for this request, you don't want the `Accept` header at all
  const { loading, error, data: todos } = useFetch(globalOptions => {
    delete globalOptions.headers.Accept
    return {
      data: [],
      ...globalOptions
    }
  }, []) // onMount

This line:
delete globalOptions.headers.Accept

Will delete the Accept header for all useFetch instances across an app.

⚠️ Make a Codesandbox ⚠️
https://codesandbox.io/embed/goofy-bird-yhon5?fontsize=14&hidenavigation=1&theme=dark

To Reproduce
Steps to reproduce the behavior:

  1. Go to Login page
  2. Click on "Login" button
  3. Open the console - the Todo useFetch options do not have the interceptors.request property that is defined in the global options passed to the Provider.

Expected behavior
I would expect that modifying the global options in an instance of useFetch would create a local copy and would not affect the global options in any other instances.

@alex-cory
Copy link
Collaborator

Thank you! Will get to this asap. If you get to it before me/would like to contribute, here's how.

@alex-cory
Copy link
Collaborator

alex-cory commented Apr 23, 2020

This should be fixed as of v1.0.8. If the issue persists, let me know. I'll reopen the issue.

@mercyaj
Copy link
Contributor Author

mercyaj commented Apr 29, 2020

@alex-cory unfortunately I'm still experiencing issues with this in v1.0.8. I've updated the Codesandbox to show the new issue. I believe the problem lies here. The fix merged above works for headers but not interceptors.

@alex-cory
Copy link
Collaborator

Apologies for missing that. Will get it merged today.

@alex-cory
Copy link
Collaborator

should be fixed in v1.0.10

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

Successfully merging a pull request may close this issue.

2 participants