1.0.12 • Published 2 years ago

react-axios-data v1.0.12

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

Quick Start

import {useAxiosFetch, manipulateAxiosData} from 'react-axios-data';

-> const { data, error } = useAxiosFetch({url :'',method: 'get', body: {}, headers: {}, params: {}});
-> manipulateAxiosData({
  url: '',
  method: '',
  body: {},
  headers: {},
  params: {}
}).then(({ error, data }) => {});

Installation

$ npm i react-axios-data
          or
$ yarn add react-axios-data

NOTE:

You can add default config for your project so that you don't have to pass these again and again.

axios.defaults.baseURL = "https://api.example.com";
axios.defaults.headers.common["Authorization"] = AUTH_TOKEN;
axios.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded";

NOTE:

useAxiosFetch It will only support GET method and work as custom hooks for calling list of data on initial render.
manipulateAxiosData It returns Promise and support all methods.

Example

GET

const { data, error } = useAxiosFetch({
  url: "/posts",
  params: { userId: 1 },
});

manipulateAxiosData({ url: "/posts", method: "get" }).then(
  ({ error, data }) => {}
);

CREATE

manipulateAxiosData({
  url: "/posts",
  method: "post",
  body: { title: "foo", body: "bar", userId: 1 },
  headers: {
    "Content-type": "application/json; charset=UTF-8",
  },
}).then(({ error, data }) => {});

UPDATE

manipulateAxiosData({
  url: "/posts/1",
  method: "put",
  body: {
    title: "foo",
    body: "bar",
    userId: 1,
  },
  headers: {
    "Content-type": "application/json; charset=UTF-8",
  },
}).then(({ error, data }) => {});

PATCH

manipulateAxiosData({
  url: "/posts/1",
  method: "patch",
  body: {
    title: "foo",
  },
  headers: {
    "Content-type": "application/json; charset=UTF-8",
  },
}).then(({ error, data }) => {});

DELETE

manipulateAxiosData({ url: "/posts/1", method: "delete" }).then(
  ({ error, data }) => {}
);

FILTER

manipulateAxiosData({
  url: "/posts",
  method: "get",
  params: { userId: 1 },
}).then(({ error, data }) => {});

Made with by Himanshu

1.0.12

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago