Skip to content

Provider interceptor uses cached values? #135

Closed
@revolucion

Description

@revolucion

I have created a custom Provider with (global) options to send certain headers on all requests via an interceptor. This interceptor should get a value from a context and send it with the headers, but it doesn't seem to update to the new value.

Created a CodeSandbox here

When you run it and open inspector to check the network calls, you can see that the x-token header remains null on each call, even though the 'token' value is updated in the context as showed in the console and on the component render.

The funny thing is, if I place the exact same interceptor code in the useFetch hook itself, it does send the correct header value.
Like so:

	const [request, response] = useFetch({
		interceptors: {
			request: options => {
				console.log("Interceptor called with token", state.token);
				options.headers["x-token"] = state.token;
				return options;
			}
		}
	});

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