Object spread vs. Object.assign

This isn’t necessarily exhaustive. Spread syntax options = {…optionsDefault, …options}; Advantages: If authoring code for execution in environments without native support, you may be able to just compile this syntax (as opposed to using a polyfill). (With Babel, for example.) Less verbose. Disadvantages: When this answer was originally written, this was a proposal, not standardized. … Read more

How to update nested state properties in React

In order to setState for a nested object you can follow the below approach as I think setState doesn’t handle nested updates. var someProperty = {…this.state.someProperty} someProperty.flag = true; this.setState({someProperty}) The idea is to create a dummy object perform operations on it and then replace the component’s state with the updated object Now, the spread … Read more

What’s the difference between “super()” and “super(props)” in React when using es6 classes?

There is only one reason when one needs to pass props to super(): When you want to access this.props in constructor. Passing: class MyComponent extends React.Component { constructor(props) { super(props) console.log(this.props) // -> { icon: ‘home’, … } } } Not passing: class MyComponent extends React.Component { constructor(props) { super() console.log(this.props) // -> undefined // … Read more

Are ‘Arrow Functions’ and ‘Functions’ equivalent / interchangeable?

tl;dr: No! Arrow functions and function declarations / expressions are not equivalent and cannot be replaced blindly. If the function you want to replace does not use this, arguments and is not called with new, then yes. As so often: it depends. Arrow functions have different behavior than function declarations / expressions, so let’s have … Read more

Call async/await functions in parallel

You can await on Promise.all(): await Promise.all([someCall(), anotherCall()]); To store the results: let [someResult, anotherResult] = await Promise.all([someCall(), anotherCall()]); Note that Promise.all fails fast, which means that as soon as one of the promises supplied to it rejects, then the entire thing rejects. const happy = (v, ms) => new Promise((resolve) => setTimeout(() => resolve(v), … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)