2017-02-13 5 views
0

API URL을 가져오고 action.js 파일에 추가하려는 전역 변수가 있습니다.Javascript/React에서 다른 파일의 전역 문자열 호출

mainUrl.js 내가 정의되지 않은 얻을 MAIN_URL을 CONSOLE.LOG

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"); 
      }); 
    } 
} 

action.js

const MAIN_URL="www.testexamplebeta.com" 

.

답변

2

이처럼 "글로벌"변수를 내 보내야합니다 : 감지 감사합니다

export const MAIN_URL="www.testexamplebeta.com" 
+0

오! – lost9123193