Category: JavaScript

Async await vs then

When working with API requests in React you can choose if you want to work with a promise syntax and make use of .then() or if you want to use async and await. below are examples of both: this code can be refactored by using async and await.

Fixing isseus with THIS in React

above code is broken as this is undefined in legacy react it would be solved by adding a constructor that binds this to this 🙂 Another example: When trying to hit enter, we get back “TypeError: Cannot read property ‘state’ of undefined ” the reason being that this function equals to and whenever the function …

Event handlers in React

Simple event handlers in React it makes sense to refactor the code above and make use of a single line arrow function instead when the onChange event triggers a very simple single line functionality, as below: However, we now have a UNCONTROLLED component where the value is stored in the HTML. This is not OK! …

Rest and Spread operators in JS

By placing … before the arrayname as you are passing the array as a argument when calling a function, you can split an array up so the function will see each array value as different arguments. By placing … before an parameter in the function declaration, values that get sent when calling the function gets …