-
Notifications
You must be signed in to change notification settings - Fork 8
Open
Description
Can you tell me how can I connect this wrapper with Redux. I want to have in separate file this wrapper and I need to dispatch some actions inside function for example for adding header.
File should looks like this but I'm getting dispatch is not defined error:
import { authGetToken } from "../store/actions/index";
const fetchWrap = require("fetch-wrap");
customFetch = fetchWrap(fetch, [
function(url, options, fetch) {
// add headers
console.log("In fetch wrap!");
dispatch(authGetToken())
.then(token => {
return fetch(
url,
fetchWrap.merge({}, options, {
headers: {
Authorization: "bearer " + token
}
})
);
})
.catch(err => {
console.log("Error while trying to get token with AuthGetToken");
});
},
]);
export default customFetch;
Metadata
Metadata
Assignees
Labels
No labels