How to Implement Data Polling With React, Redux, and Thunk

Introduction

In my previous article, Loading Data in React: Redux-Thunk, Redux-Saga, Suspense, and HooksI compared different ways of loading data from the API. Quite often in web applications, data needs to be updated frequently to show relevant information to the user. Short polling is one of the ways to do it. Check out this article for more details and alternatives.

Briefly, we are going to ask for new data every N milliseconds. We then show this new data instead of the previously loaded data. This article gives an example of how to do it using React, Redux, and Thunk.

Loading Data in React: Redux-Thunk, Redux-Saga, Suspense, and Hooks

Introduction

React is a JavaScript library for building user interfaces. Very often using React means using React with Redux. Redux is another JavaScript library for managing global state. Sadly, even with these two libraries, there is no one clear way to handle asynchronous calls to the API (backend) or any other side effects.

In this article, I’m trying to compare different approaches to solving this problem. Let’s define the problem first.