Closed
Description
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
Labels
No labels