Javascript에서 constants 관리하기
May 28, 19
dev
react
javascript
/components/users/constants.js
const userStatesActive = 0;
const userStatesInActive = 1;
const userStatesLabels = {
[userStatesActive]: "active user",
[userStatesActive]: "active user"
};
export default {
userStatesActive,
userStatesInActive,
userStatesLabels
};
/components/users/userStates.jsx
import {userStatesLabels} from './constants'
...
render{
const {state} = this.props;
return (
<span>{userStatesLabels[state]}</span>
)
};