Dealing With Null Data in Javascript Using Nullish Coalescing

The nullish coalescing (??) operator is a logical operator that returns its right-hand side operand when its left-hand side operand is null or undefined, and otherwise returns its left-hand side operand. Earlier, when one wanted to assign a default value to a variable, a common pattern was to use the logical OR operator (||): let foo; // foo is never assigned any value so it is still undefined const someDummyText = foo || "Hello!...

January 9, 2023 · 2 min · Daman Arora

Tracing a Function Call in Javascript Using Console

In JavaScript we’re often working in the context of deeply nested functions and objects. When debugging our code, it may be necessary to traverse through the stack trace of our code. In order to do that, we can use console.trace() in the function that we would expect to be at the top of the call stack. Using console.trace() we can see exactly what happened before our function was pushed on to the top of the call stack....

January 3, 2023 · 1 min · Daman Arora

Three Major Ways to Style a React Component

Inline CSS This is the CSS styling sent to the element directly using the HTML or JSX. You can include a JavaScript object for CSS in React components, although there are a few restrictions such as camel casing any property names which contain a hyphen. Example: import React from "react"; const spanStyles = { color: "#fff", borderColor: "#00f" }; const Button = props => ( <button style={{ color: "#fff", borderColor: "#00f" }}> <span style={spanStyles}>Button Name</span> </button> ); Styled-Components Styled-components is a library that utilizes tagged template literals — which contain actual CSS code between two backticks — to style your components....

January 1, 2023 · 2 min · Daman Arora

Using a List to Render Multiple React Components

You can build collections of elements and include them in JSX using curly braces {}. Below, we loop through the numbers array using the JavaScript map() function. We return a <li> element for each item. Finally, we assign the resulting array of elements to listItems: const numbers = [1, 2, 3, 4, 5]; const listItems = numbers.map((number) => <li>{number}</li> ); Then, we can include the entire listItems array inside a <ul> element:...

January 1, 2023 · 2 min · Daman Arora

Remember Data Down Action Up in React

“Data down, Action up” This phrase helps developers understand the flow of information from parent to child component and vice versa. The first and more simple concept, “data down,” refers to the passing of data and/or functions via props from parent to child components. These props are passed down when a child component gets created. We pass data down to child components so they can render them on to the DOM....

December 30, 2022 · 1 min · Daman Arora