Web Development

Understanding the useRef React hook

Understanding the useRef React hook

  • January 21, 2021

Continuing our React hooks series, we will learn about the useRef React hook in this blog post. The useRef React hook is useful in the following two situations: Before we see these advantages of the hook, let us first understand what the hook is and what it does. What is...

How to cancel an HTTP fetch request

How to cancel an HTTP fetch request

  • January 19, 2021

JavaScript promises have been a huge catalyst for asynchronous coding in the language. They have vastly improved the performance and experience for web development. One shortcoming of native promises has been that we were not able to cancel an HTTP fetch request once it was initiated. But now there is...

Use redux-like middleware for useReducer in React

Use redux-like middleware for useReducer in React

  • January 14, 2021

If you have used Redux before, you would be aware of the concept of middlewares. Now that useReducer has become a commonly used react hook, we might want to replicate the idea of middleware for the useReducer hook as well. If you do not know about middlewares, middlewares are functions...

How to write your own custom React hooks

How to write your own custom React hooks

  • January 12, 2021

If you have been using react for a while, chances are you have come across the need to extract some logic into a reusable function. And with React hooks coming into the picture, doing this has become a walk in the park. We can write our own custom react hooks...

Provide callback to useState hook like setState

Provide callback to useState hook like setState

  • December 15, 2020

If you have been writing class components for a while, you might be familiar with the callback functionality that the setState function provides. setState allows a second parameter to be passed to it as a callback. The callback function is invoked whenever the state of the function gets updated. But,...

Resolving nested queries in GraphQL

Resolving nested queries in GraphQL

  • December 8, 2020

When creating a GraphQL server with relational data, we want to return the data in a hierarchical format with those relationships in a single query. After all, that is where GraphQL comes in handy, right? Let us look into how we can do this using nested queries in GraphQL. This...

Creating a GraphQL API with Apollo Server

Creating a GraphQL API with Apollo Server

  • December 2, 2020

One of the many complaints about the GraphQL ecosystem is that there is a lot of indirection around what packages to use to create a GraphQL application. Even after selecting one, there is a lot of boilerplate code that one must create to make a GraphQL server work. While that...

How to unit-test a private (non-exported) function in JavaScript

How to unit-test a private (non-exported) function in JavaScript

  • November 19, 2020

When writing unit-tests for JavaScript modules, we often encounter a dilemma wherein the module has some private functions that have not been exported. Testing a function that has been exported is easy since it can be imported in the unit testing framework, and the functionality can be tested. But how...