All Projects → zaingz → use-axios-hooks

zaingz / use-axios-hooks

Licence: MIT license
axios hooks for common network calls scenarios

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects
CSS
56736 projects

Projects that are alternatives of or similar to use-axios-hooks

add-my-name
No more WhatsApp spams 🎉
Stars: ✭ 16 (-40.74%)
Mutual labels:  axios, react-hooks
MovieCards
React App that uses TMDb API to display movie data. Try it out! ->
Stars: ✭ 38 (+40.74%)
Mutual labels:  axios, react-hooks
laravel-react-boilerplate
Laravel React Boilerplate with Ant Design, Route-Level Code Splitting, Redux, Sanctum Auth
Stars: ✭ 49 (+81.48%)
Mutual labels:  axios, react-hooks
react-hooks-file-upload
React Hooks File Upload example with Progress Bar using Axios, Bootstrap
Stars: ✭ 30 (+11.11%)
Mutual labels:  axios, react-hooks
shop-app
A shopping mobile application made with react native for Android.
Stars: ✭ 100 (+270.37%)
Mutual labels:  axios, react-hooks
react-admin-nest
React和Ant Design和 Nest.js 和 Mysql 构建的后台通用管理系统。持续更新。
Stars: ✭ 123 (+355.56%)
Mutual labels:  axios, react-hooks
react-vite-admin
This Starter utilizes React, Recoil, React Query, React Hooks, Typescript, Axios And Vite. 全新技术栈的后台管理系统
Stars: ✭ 90 (+233.33%)
Mutual labels:  axios, react-hooks
React Cloud Music
React 16.8打造精美音乐WebApp
Stars: ✭ 1,722 (+6277.78%)
Mutual labels:  axios, react-hooks
react-app-simple-chat-app
A Simple Chat Application using MERN stack (MongoDB, Express JS, React JS, Node JS) and Socket.io for real time chatting
Stars: ✭ 41 (+51.85%)
Mutual labels:  axios, react-hooks
proffy
React Native + ReactJS + NodeJS project developed on RocketSeat NexLevelWeek. This project is based on an application for connect students and teachers.
Stars: ✭ 30 (+11.11%)
Mutual labels:  axios
Vue2.x-mobileSystem
基于Vue2.0的移动端项目,项目没有使用vue-cli,全部手写,让小白更容易学习理解
Stars: ✭ 72 (+166.67%)
Mutual labels:  axios
wwvue-cli
vue-cli升级版脚手架,应有尽有的开箱即用方法及配置,没有花里胡哨的晦涩难懂的操作,上手成本极低,现已新增simple(极简模式)、vue3和iview-template,是个很不错的垫脚石,来不及解释了赶紧上车😊😘
Stars: ✭ 15 (-44.44%)
Mutual labels:  axios
axios-curlirize
axios plugin converting requests to cURL commands, saving and logging them.
Stars: ✭ 152 (+462.96%)
Mutual labels:  axios
rocketshoes-react-native
NetShoes Clone with React Native and Redux
Stars: ✭ 38 (+40.74%)
Mutual labels:  axios
madao admin manage
🎉 VUE前后端分离管理系统,基于RBAC的后台管理。
Stars: ✭ 38 (+40.74%)
Mutual labels:  axios
spring-file-poller
A simple spring boot application that demonstrates file polling using the Spring Integration DSL
Stars: ✭ 25 (-7.41%)
Mutual labels:  polling
vue-mintUI-demo
采用vue2、Mint UI,做的移动端项目
Stars: ✭ 17 (-37.04%)
Mutual labels:  axios
quiz
⚛️ Sample Quiz App using React Hooks (useReducer() + useContext()). This app was created for a React Hooks tutorial, if you want to follow the tutorial on Youtube click on the link 👉
Stars: ✭ 26 (-3.7%)
Mutual labels:  react-hooks
ts-vue-questionnaire
微型问卷调查系统 TypeScript 版本,演示账号:admin / admin
Stars: ✭ 89 (+229.63%)
Mutual labels:  axios
Frontend
마음을 잇는 현명한 소비 '잇다'🤝
Stars: ✭ 19 (-29.63%)
Mutual labels:  react-hooks

use-axios-hooks

axios hooks for common network calls scenarios

npm version JavaScript Style Guide GitHub license Maintenance

Read here about my motivation for developing this library: https://medium.com/@zaingz/how-react-hooks-compares-to-redux-eba43788df46

Features

  • Simple and easy to use, no configuration needed.
  • Built on top of axios api.
  • Ability to retry if api call fails.
  • Ability to do api polling.
  • Ability to cancel in flight api calls.
  • Plays nicely with react component life cycle.

Installation

npm install --save axios use-axios-hooks

Axios is peerDependency of this lib so make sure you install axios separately.

Usage

import  React,  {  Component  }  from  'react'
import  { useAxios }  from  'use-axios-hooks'


const  Example  =  ()  =>  {
const  [{data, isLoading, error, isCanceled},  cancel] = useAxios('http://my-awesome-api/endpoint')

return (
  <div>
    {isLoading  &&  'Loading...'}
    {data && JSON.stringify(data)}
    {error && JSON.stringify(error)}
    <button onClick={() => cancel()}>cancel</button>
  </div>
)
}

Retry on error:

import  React,  {  Component  }  from  'react'
import  { useAxiosRetry }  from  'use-axios-hooks'


const  Example  =  ()  =>  {
const  [{data, isLoading, error, isCanceled},  cancel] = useAxiosRetry(
    "https://api-will-fail/retry",
    {
      retryCount: 2,
      retryInterval: 2000
    }
  );

return (
  <div>
    {isLoading  &&  'Loading...'}
    {data && JSON.stringify(data)}
    {error && JSON.stringify(error)}
    <button onClick={() => cancel()}>cancel retrying</button>
  </div>
)
}

Polling:

import  React,  {  Component  }  from  'react'
import  { useAxiosInterval }  from  'use-axios-hooks'


const  Example  =  ()  =>  {
const  [{data, isLoading, error, isCanceled},  cancel] = useAxiosInterval(
    "https://awesome-api/poll",
    4000
  );

return (
  <div>
    {isLoading  &&  'Loading...'}
    {data && JSON.stringify(data)}
    {error && JSON.stringify(error)}
    <button onClick={() => cancel()}>cancel polling</button>
  </div>
)
}

Edit practical-sky-tpi6c

API

useAxios(url | config)

Basic hook to make network calls.

Returns [{data, isLoading, error, isCanceled}, cancel]

  • data The response object returned by axios.
  • isLoading Boolean to indicate if request is started but not completed.
  • error Error object returned by axios.
  • isCancelled Boolean to indicate if request is canceled.
  • cancel Function to cancel pending network call. (It uses axios cancellation api).

useAxiosRetry(url | config, options)

Hook to retry network call on error.

  • url | config The request url or axios request config object.

  • options Configuration to specify retry options i.e { retryCount: number, retryInterval: milliseconds }

Returns [{data, isLoading, error, isCanceled}, cancel]

  • data The response object returned by axios.
  • isLoading Boolean to indicate if request is started but not completed.
  • error Error object returned by axios.
  • isCancelled Boolean to indicate if request is canceled.
  • cancel Function to cancel retying.

useAxiosInterval(url | config, interval)

Hook to do repeated network call after an interval (long polling).

  • url | config The request url or axios request config object.

  • interval Interval in milliseconds in which network will be made.

Returns [{data, isLoading, error, isCanceled}, cancel]

  • data The response object returned by axios.
  • isLoading Boolean to indicate if request is started but not completed.
  • error Error object returned by axios.
  • isCancelled Boolean to indicate if request is canceled.
  • cancel Function to cancel the polling.

License

MIT © zaingz


This hook is created using create-react-hook.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].