Where to put enums in my react application
if I understand correctly what you need.... in one of your file like newfile.js you have to import your enum file like this:
import { USER_TYPES, USER_STATUS,FOLLOWING_STATUS } from './enums'
note: './enums' is a path ... so here you have to put your path
and use as normal constant like this:
USER_TYPES.USER // is it string "user",
USER_TYPES.TRAINER // is it string "trainer",
USER_TYPES.ADMIN // is it string "admin",
USER_STATUS.REQUESTED //is it string "Requested",
FOLLOWING_STATUS.FOLLOWING //is it number 1,
For a more semantic use, you could rename and move your file from config/enum.js
to constants/users.js
.
There you export each object your want, but with a shortened name:
USER_TYPE
-> TYPES
, USER_STATUS
-> STATUS
.
So when you import your file you can do: import * as USERS from 'constants/users;
and use it like this: USERS.STATUS.FOLLOW
.