<aside> ⚠️ 잘 안될 경우: i. 시뮬레이터 재시작 ii. expo start -c 실행 (캐시 초기화)
</aside>
Using environment variables in a React Native App.
yarn add "@types/react-native-dotenv"
# Shoong EC2 instance end point
API_BASE_URL=http://k6a103.p.ssafy.io:8081
“plugins”
아래에 아래 코드 추가[
'module:react-native-dotenv',
{
moduleName: '@env',
path: '.env',
blacklist: null,
whitelist: ['API_BASE_URL'], // 여기에 환경변수들 추가
safe: false,
allowUndefined: true,
},
],
~/types
폴더 아래에 env.d.ts
파일 생성declare module '@env' {
export const API_BASE_URL: string;
}
tsconfig.json
의 “compilerOptions”
안에 다음을 추가
"typeRoots": ["./src/types"]
import { Text } from 'react-native';
import { API_BASE_URL } from '@env';
const Test = () => {
return (
<Text>{API_BASE_URL}</Text>
);
};
export default Test;