How I Created My Own React Spinners Library

Josh Kuttler

I’ve created an application that uses Airtable as a database. I’ve used a spinner to take the place of a dull blank page which would otherwise be presented to the user in the time that it takes for the requested data to arrive and for the page to get rendered accordingly.

I could have used an existing react spinners library, but instead, I decided to use this chance to learn how to build my own spinners and my own React component library. So, in this post, I’ll show you my library, and an example of how to use a spinner.

React Spinners Library

So, without further ado, here’s my react spinners library (GitHub, Bit). It’s based on CSS loaders. I’ve added the option to send color and size as props of the component so that it’s easier to customize the spinners. I’ve exported the spinners (twelve in total) to so you may easily view and tweak them in Bit’s live playground, and install them as packages with NPM or Yarn (or get their source code using Bit import).

For example, this is the circle loader and the component can receive color and size props:

and the code import a very simple CSS code, exactly the same from CSS loader:

How to use Loader animation in your React.js application?

So, you have a component that sends a request and stores the received data in an array inside your state object. The obvious thing to do is check if the array is empty and if so, display the spinner.

For this example, I used a Facebook spinner with a very simple page that waiting 5 seconds until to show a list of cars.

It’s very simple to use and allows you to show a nice animation loader until the data is loaded.

Also, you can use a custom color in any spinner, just send a color inside the color property, like this:

<Facebook color="red" />
<Facebook color="#cecece" />

Or be crazy and use a random color with my random color generator component.

<Facebook color={getRandomColor()} />

You can see the result with random color in this live demo facebook react spinner.

If you want to see more react spinners examples, check out my react spinners components collection in

For any issue or missing features, please open an issue on GitHub and I’ll do my best.

And of course, if you like it, star it!

And follow me on Twitter to get features updates.

Josh Kuttler

Written by

I develop web apps for work, and I’m creating games with Unity & React Native for fun. My true love is JavaScript 🖤💫💻

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade