Skip to main content

Constant(s)

What is a constants file?

A constants file is a dedicated file to store declared constant properties. The beauty of this file is that it’s accessible globally throughout the app.

Declare A Constant

ES6 provides a new way of declaring a constant by using the const keyword. The const keyword creates a read-only reference to a value. By convention, the constant identifiers are in uppercase.

export const MAX_FILE_SIZE = 1048576 * 100;

Folder Structure

  • /constants
    • {constantsGroupName}.js
    • index.js

Folder Structure Sample

image-1654083393467.png

Constants File Sample

export const MAX_FILE_SIZE = 1048576 * 100; // 100 MB

export const FILE_UPLOAD_ACCEPTS_IMAGES = "image/jpg,image/jpeg,image/png,image/gif,image/tiff,image/webp";
export const FILE_UPLOAD_ACCEPTS_VIDEOS = `video/mp4,video/quicktime,video/mov,video/avi,video/mpg,video/wmv,video/x-m4v,video/webm,video/x-matroska,video/x-msvideo,video/x-ms-asf,video/x-ms-wmv,video/x-flv,video/3gpp,video/ogg`;
export const FILE_UPLOAD_ACCEPTS_IMAGES_VIDEOS = `${FILE_UPLOAD_ACCEPTS_IMAGES},${FILE_UPLOAD_ACCEPTS_VIDEOS}`;

Constant Files Grouping Sample: index.js

export * from "@constants/fileUploads";
export * from "@constants/hotkeyShortcuts";
export * from "@constants/languages";
export * from "@constants/theme";