What is the difference between using constructor vs state = {} to declare state in react component?

They are roughly equivalent. The significant difference is that the initializer in the second example is executed before constructor. The second approach uses class fields proposal. It is not a part of ECMAScript standard yet so you need to set up transpiler properly to use the second approach. UPD Take a look at Babel output … Read more

How to avoid bind or inline arrow functions inside render method

First: A simple solution will be to create a component for the content inside a map function and pass the values as props and when you call the function from the child component you can pass the value to the function passed down as props. Parent deleteTodo = (val) => { console.log(val) } todos.map(el => … Read more

What are the differences between the private keyword and private fields in TypeScript?

Private keyword The private keyword in TypeScript is a compile time annotation. It tells the compiler that a property should only be accessible inside that class: class PrivateKeywordClass { private value = 1; } const obj = new PrivateKeywordClass(); obj.value // compiler error: Property ‘value’ is private and only accessible within class ‘PrivateKeywordClass’. However compile … Read more

Correct use of arrow functions in React

I understand that arrow functions make things more efficient by not recreating the functions each time they are referred to This is not true. Arrow functions handles the this context in a lexical way, where “normal” function do it dynamically. I wrote about the this key word in depth if you need more info about … Read more

How do I make a “public static field” in an ES6 class?

You make “public static field” using accessor and a “static” keyword: class Agent { static get CIRCLE() { return 1; } static get SQUARE() { return 2; } } Agent.CIRCLE; // 1 Looking at a spec, 14.5 — Class Definitions — you’d see something suspiciously relevant 🙂 ClassElement[Yield] :   MethodDefinition[?Yield]   static MethodDefinition[?Yield] ; So from … Read more

How to use arrow functions (public class fields) as class methods?

Your syntax is slightly off, just missing an equals sign after the property name. class SomeClass extends React.Component { handleInputChange = (val) => { console.log(‘selectionMade: ‘, val); } } This is an experimental feature. You will need to enable experimental features in Babel to get this to compile. Here is a demo with experimental enabled. … Read more

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