const or let in React component

const is a signal that the variable won’t be reassigned. let is a signal that the variable may be reassigned Additional things to ponder: Use const by default Use let only if rebinding is needed const does not indicate that a value is ‘constant’ or immutable. const foo = {}; foo.bar = 10; console.log(foo.bar); // … Read more

How to find multiple elements in Array – Javascript ,ES6

You have to use filter at this context, let names= [“Style”,”List”,”Raw”]; let results= names.filter(x => x.includes(“s”)); console.log(results); //[“List”] If you want it to be case insensitive then use the below code, let names= [“Style”,”List”,”Raw”]; let results= names.filter(x => x.toLowerCase().includes(“s”)); console.log(results); //[“Style”, “List”] To make it case in sensitive, we have to make the string’s character … Read more

Function or fat arrow for a React functional component? [duplicate]

There is no practical difference. An arrow allows to skip return keyword, but cannot benefit from hoisting. This results in less verbose output with ES6 target but more verbose output when transpiled to ES5 , because a function is assigned to a variable: var MyMainComponent = function MyMainComponent() { return React.createElement( “main”, null, React.createElement(“h1”, null, … Read more

How do I require() from the console using webpack?

Here’s another more generic way of doing this. Requiring a module by ID The current version of WebPack exposes webpackJsonp(…), which can be used to require a module by ID: function _requireById(id) { return webpackJsonp([], null, [id]); } or in TypeScript window[‘_requireById’] = (id: number): any => window[‘webpackJsonp’];([], null, [id]); The ID is visible at … Read more

How to use es6 template literal as Angular Component Input

ES6 Template literals (Template strings) cannot be used inside an Angular component input, because the Angular compiler doesn’t know this grammar. The way that you provided is fine. <app-my-component [myInput]=”‘My name is ‘ + name + ‘!'”></app-my-component> Or something like this, In the component, // In the component, you can use ES6 template literal name: … Read more