The Modern Way to Use Promise- Based HTTP Requests: axios-hooks

React Hooks for axios, with built-in support for server-side rendering

Riccardo Giorato
Nov 22, 2019 · 2 min read

What’s axios-hooks?

You might need to make requests to your own or external API in your React app and you usually needed to use Promises to get the results back, trying to use them inside your React components with the axios library.

Axios-hooks is here to solve this problem with a simpler syntax using the complete power of React Hooks in a few lines of code.


All the axios awesomeness you are familiar with but simplified with Hooks.


To install it with npm:

npm install axios axios-hooks

To install it with Yarn:

yarn add axios axios-hooks

Axios is a peer dependency and needs to be installed explicitly.

How Do I Use It?

It will feel easy, like using useQuery from Apollo React with GraphQL queries.


This hook will return three simple elements:

You will access the useAxios Hook to do almost every operation and, in some cases, also the configure Hook to define an API-base endpoint URL.

import { configure } from 'axios-hooks'
import LRU from 'lru-cache'
import Axios from 'axios'

const axios = Axios.create({
baseURL: ''

const cache = new LRU({ max: 10 })

configure({ axios, cache })

CodeSandbox React axios Playground

If you want to learn more about Hooks

I have personally read Learn React Hooks when I started using hooks and it helped me understand them to use tools such as useAxios:

Better Programming

Advice for programmers.

Riccardo Giorato

Written by

XR Developer and Photogrammetry Artist

Better Programming

Advice for programmers.

More From Medium

More from Better Programming

More from Better Programming

More from Better Programming

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