Skip to content

Connecting with redux #7

@jahicDario

Description

@jahicDario

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions