JavaScript Using enum in ES2015

How do I use enums in ES2015? I tried the following but I'm getting errors:

Created a file for my enums i.e. errorTypes.js

export const Types = {
   MISSING_DATA: 0,
   INVALID_DATA: 1
}

I then tried to import this into my React component and use it as follows:

import errorTypes from '../enums/errorTypes';

handleOnClick(event) {

   // Some logic here
   const newError = {type: errorTypes.INVALID_DATA, message: "Please type carefully!"};

}

The error I'm getting is

Uncaught TypeError: Cannot read property 'INVALID_DATA' of undefined

Answer:1

While attempting to use React.js and maybe or most likely I am doing something wrong? But when I run React.Render() nothing visible renders, however. Viewing the DOM through Chromes console I can see ...

While attempting to use React.js and maybe or most likely I am doing something wrong? But when I run React.Render() nothing visible renders, however. Viewing the DOM through Chromes console I can see ...

given the following: constructor () { super(); this.state = { inputs : [ { type: 'email', placeholder: 'Email Address' } ] }; } render () { return { &...

given the following: constructor () { super(); this.state = { inputs : [ { type: 'email', placeholder: 'Email Address' } ] }; } render () { return { &...

  1. loop over form controls angular
  2. loop over formarray
  3. loop over form data
  4. loop over formgroup controls
  5. loop over form javascript
  6. loop through form controls angular
  7. loop through form elements jquery
  8. loop through form elements javascript
  9. loop through form elements
  10. loop through formarray
  11. loop through form inputs jquery
  12. loop through form data
  13. angular loop through formarray
  14. loop through form controls vba
  15. loop through form fields django
  16. loop through form controls
  17. loop through form inputs
  18. loop through form group
  19. loop through form fields javascript
  20. loop through form fields jquery

I have the following javascript function that prevents form submission if all required fields are not complete and is part of a form I am creating using Google Apps Scripts. Note that the #...

I have the following javascript function that prevents form submission if all required fields are not complete and is part of a form I am creating using Google Apps Scripts. Note that the #...

I have an action creator which does an expensive calculation and dispatches an action every time the user inputs something (basically real time updating). However, if the user inputs multiple things, ...

I have an action creator which does an expensive calculation and dispatches an action every time the user inputs something (basically real time updating). However, if the user inputs multiple things, ...