Skip to content

Release Notes v1.0.1

Choose a tag to compare

@smartlabsAT smartlabsAT released this 10 Feb 19:50
· 28 commits to main since this release

We are thrilled to announce the first release of react-axios-provider! This release introduces a minimal React context provider that supplies a shared Axios instance throughout your application.

Features

  • Shared Axios Instance:
    Easily access a single, centrally managed Axios instance anywhere in your React tree.
  • Dynamic Instance Update:
    Replace your Axios instance on the fly using the updateAxios() function, allowing you to update configurations such as base URLs, headers, or interceptors. 🚀

Installation

npm install react-axios-provider

Basic Usage

Wrap your application with the provider and pass in your pre-created Axios instance:

import { AxiosProvider } from 'react-axios-provider';
import axios from 'axios';

const axiosInstance = axios.create({ baseURL: 'https://api.example.com' });

function App() {
  return (
    <AxiosProvider instance={axiosInstance}>
      <YourComponents />
    </AxiosProvider>
  );
}

Then, in any component, consume the context using the provided hook:

import { useAxiosContext } from 'react-axios-provider';

function MyComponent() {
  const { axios, updateAxios } = useAxiosContext();

  // Use axios to make API calls, or update it dynamically
  // Example:
  // const fetchData = async () => {
  //   const response = await axios.get('/endpoint');
  //   console.log(response.data);
  // };

  // To update the axios instance:
  // updateAxios(newAxiosInstance);
}

Why Use react-axios-provider?

  • Simplicity:
    No need to pass down Axios props manually—get your Axios instance globally with ease.
  • Flexibility:
    Dynamically update your Axios instance as your app's configuration changes.
  • Centralization:
    Maintain all your API configuration in one place for easier management. ✨

Thank you for using react-axios-provider! Your feedback and contributions are welcome. Enjoy building amazing apps! 😎🎉