importing env variable react front end

You don’t need dotenv (and I doubt that library will work at runtime in a client-side application anyway). create-react-app actually provides this functionality out of the box, assuming you’re using react-scripts@0.5.0 or higher. The steps are as follows: Create a .env file in the root of your project. Add a variable, starting with the prefix … Read more

Can I use continue and break in Javascript for…in and for…of loops?

Yep – works in all loops. const myObject = { propA: ‘foo’, propB: ‘bar’ }; for (let propName in myObject) { console.log(propName); if (propName !== ‘propA’) { continue; } else if (propName === ‘propA’) { break; } } (By loops I mean for, for…in, for…of, while and do…while, not forEach, which is actually a function … Read more

Arrow Function in Object Literal [duplicate]

Note that the Babel translation is assuming strict mode, but your result with window indicates you’re running your code in loose mode. If you tell Babel to assume loose mode, its transpilation is different: var _this = this; // ** var arrowObject = { name: ‘arrowObject’, printName: function printName() { console.log(_this); // ** } }; … Read more

ESLint warning ES6 consistent-return rule

http://eslint.org/docs/rules/consistent-return says: This rule requires return statements to either always or never specify values. When your if-condition is not met, the arrow function will terminate without encountering a return statement, which violates this rule. Your second version violates this rule because your second return does not specify a value, contrary to the first return. The … Read more