0

I have a global variable that fetches an API URL and I want to add it to my action.js file.

mainUrl.js

const MAIN_URL="www.testexamplebeta.com"

action.js

import {MAIN_URL} from '../mainUrl'

export function fetchPets() {
    return function(dispatch) {
        console.log("THE URL IS", MAIN_URL)
        axios.get(`${MAIN_URL}/tests`)
            .then(response => {
                dispatch({
                    type: FETCH_TESTS,
                    payload: response
                });
            })
            .catch(() => {
                console.log("Can't fetch the test examples");
            });
    }
}

When I console.log the MAIN_URL I get undefined.

1 Answer 1

4

You should export your "global" variable like this:

export const MAIN_URL="www.testexamplebeta.com"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.