Code Support
Professional Web Development
Category: React
Destructuring an array
can be refactored by destructuring the array when calling the .map function
October 24, 2020
JavaScript, React
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.
October 24, 2020
JavaScript, React
Passing data from Child to Parent in React
create a prop on the child element that calls a function pass the data in the child component to the function that was passed down as a prop App.js now got the search term that was filled in child component!
October 23, 2020
Articles, Code, JavaScript, React
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 …
October 23, 2020
JavaScript, React
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! …
October 23, 2020
JavaScript, React
Simple Function refactored into a class
refactored into a class
October 22, 2020
Code, JavaScript, React
if-else statement and duplicate ternery expressions refactored
If we have duplicate code like this: it can be refactored into a if-else statement: but even better would be to create a seasonConfig object!
October 22, 2020
JavaScript, React