Skip to content

Deleting a global option persists for all instances #250

Closed
@mercyaj

Description

@mercyaj

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions