Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@cicara/react-axios

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cicara/react-axios

react axios wrapper

  • 0.0.1-6
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6
Maintainers
1
Weekly downloads
 
Created
Source

React Axios

React Axios is a React library based on Axios that aims to provide better HTTP request handling capabilities for React applications. The library provides an AxiosProvider component that makes it easy to use Axios throughout your entire React application, and includes a useAxios hook and some customizable interceptors.

Installation

npm install @cicara/react-axios

Usage

To use Axios in your React components, you need to provide an AxiosProvider component in your application. In the AxiosProvider component, you can set the configuration for the Axios instance, and add interceptors for custom handling.

import { useEffect } from "react";
import { useAxios, AxiosProvider } from "@cicara/react-axios";

function TestAxios() {
  const axios = useAxios();

  useEffect(
    () => {
      const ac = new AbortController();

      // GET request to `/base/url/test?_t=1682750920279`
      axios.get("/test", { signal: ac.signal })
        .catch((err) => {
          console.error(err);
        });

      return () => {
        ac.abort();
      };
    }, 
    [axios],
  );

  return (
    <div>Axios Test</div>
  );
}

export default function App() {
  return (
    <AxiosProvider
      config={{
        baseURL: "/base/url"
      }}
      interceptors={[
        {
          name: "timestamp",
          request: {
            onFulfilled(request) {
              request.params = {
                _t: Date.now(),
                ...request.params,
              };
              return request;
            }
          }
        }
      ]}>
      <TestAxios />
      <AxiosProvider
        config={{
          baseURL: "/base/url2"
        }}
        interceptors={[
          {
            name: "auth",
            request: {
              onFulfilled(request) {
                request.headers.Authorization = `Bearer ${localStorage.getItem('token')}`;
                return request;
              }
            }
          }
        ]}>
        <TestAxios />
      </AxiosProvider>
    </AxiosProvider>
  );
}

Keywords

FAQs

Package last updated on 09 Jun 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc