Is it possible to do multiple class imports with ES6/Babel?

You can export like this: import App from ‘./App’; import Home from ‘./Home’; import PageWrapper from ‘./PageWrapper’; export { App, Home, PageWrapper } Then, you can import like this wherever you need it: import { App, PageWrapper } from ‘./index’ //or similar filename … You can read more about import and export here. I also … Read more

what does super() do without any arguments?

In ES6, derived classes have to call super() if they have a constructor. In react, all components extend from the Component class. You don’t actually need a constructor for every ES6/react class. If no custom constructor is defined, it will use the default constructor. For base classes, it is: constructor() {} And for derived classes, … Read more

How to specify a constructor with a functional component (fat arrow syntax)?

Since it’s a stateless component it doesn’t have the component lifecycle. Therefor you can’t specify a constructor. You have to extend React.Component to create a stateful component which then will need a constructor and you’ll be able to use the state. Update Since React 16.8.0 and Hooks got introduced there are more options. Hooks are … Read more

What is the most efficient way to copy some properties from an object in JavaScript?

You can achieve it with a form of destructuring: const user = { _id: 1234, firstName: ‘John’, lastName: ‘Smith’ }; const { _id, …newUser } = user; console.debug(newUser); Browser support: The spread (…) syntax was introduced with ES2018, and most browsers even supported it before ES2018 was finalized. So as of 2023, you can rely … Read more

destructuring assignment default value [duplicate]

You probably confused by the difference between null and undefined, For example: const { dogName=”snickers” } = { dogName: undefined } console.log(dogName) // what will it be? ‘snickers’! const { dogName=”snickers” } = { dogName: null } console.log(dogName) // what will it be? null! const { dogName=”snickers” } = { dogName: false } console.log(dogName) // … Read more

How to replace /n to linebreaks in react.js?

An alternative to this would be to use css to display it with line breaks. This also makes it easier to copy and paste with the original line breaks as well as distinguishing between one break (\n) and two breaks (\n\n). Just add the style white-space: pre-wrap; to your element. <div style={{whiteSpace: “pre-wrap”}}>{note.note}</div> There are … Read more