상세 컨텐츠

본문 제목

default 와 Object import 문

JavaScript

by 폴리프레임 2024. 4. 3. 15:38

본문

반응형

Constant.js 파일

export const COLORS = {
	primary: '#13678A', white: "#FFFFFF",
}
export default {
	light: {
		text: '#000',
		background: '#fff',
		tabIconDefault: '#ccc',
	},
	dark: {
		text: '#fff',
		background: '#000',
		tabIconDefault: '#ccc',
	}
};

 

위와 같은 경우, 다른 파일에서 불러 올때는 다음과 같이 부릅니다.

 

import customTheme, { COLORS } from './Constant.js';

// customTheme 사용 예시
console.log(customTheme.light); // { text: '#000', background: '#fff', tabIconDefault: '#ccc' }
console.log(customTheme.dark); // { text: '#fff', background: '#000', tabIconDefault: '#ccc' }

// COLORS 사용 예시
console.log(COLORS.primary); // '#13678A'
console.log(COLORS.white); // '#FFFFFF'

즉 default 의 경우는 별도의 이름을 붙이고, customTheme, 객체의 경우는 destructing 후 객체명을 이용하여 부릅니다.

'JavaScript' 카테고리의 다른 글

firebase hosting + vite.js  (0) 2024.04.17
Vite.js 에서 환경변수 사용 .env  (1) 2024.04.17
JavaScript 소숫점 다루기  (0) 2024.03.26
includes(), has(), size(), length() in JavaScript  (0) 2023.11.29
CommonJS module 와 ES module  (2) 2023.11.01

관련글 더보기