config.js 작성요령 (기초세팅)

Youje0·2023년 1월 30일
0

config.js에 url을 작성하여 사용하자.

<-- config.js -->
export const BASE_URL = 'url주소';

ex =>
export const BASE_URL = 'localhost:8000';

<-- app.js -->
import {BASE_URL} from "../config";

const app = () =>{

const URL = `https://${BASE_URL}/`
<-- BASE_URL의 값이 들어간다 -->
  useEffect(() => {
    fetch(URL)
      .then(res => res.json())
      .then(json => setData(json.data));
  }, []);

...
}

이런식으로 config.js에 url주소를 작성하여 import해서 사용했을때 최종적으로 build할때
실제 url 주소를 한번에 바꿀 수 있어 용이하다.

profile
ㅠㅠ

0개의 댓글