Commit ed18b5f5 authored by Nathan Friend's avatar Nathan Friend

Merge branch 'mw-add-constant-export-to-fe-guide-style' into 'master'

Update FE guidlines

See merge request gitlab-org/gitlab!55742
parents 394e6f77 f8ec5697
......@@ -294,3 +294,24 @@ Strive to write many small pure functions and minimize where mutations occur
var c = pureFunction(values.foo);
```
## Export constants as primitives
Prefer exporting constant primitives with a common namespace over exporting objects. This allows for better compile-time reference checks and helps to avoid accidential `undefined`s at runtime. In addition, it helps in reducing bundle sizes.
Only export the constants as a collection (array, or object) when there is a need to iterate over them, for instance, for a prop validator.
```javascript
// bad
export const VARIANT = {
WARNING: 'warning',
ERROR: 'error',
};
// good
export const VARIANT_WARNING = 'warning';
export const VARIANT_ERROR = 'error';
// good, if the constants need to be iterated over
export const VARIANTS = [VARIANT_WARNING, VARIANT_ERROR];
```
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment