react-easy-fetch
TypeScript icon, indicating that this package has built-in type declarations

1.1.1 • Public • Published

react-easy-fetch

Easy React component wrapper for axios

Install

yarn add react-easy-fetch
// or
npm i react-easy-fetch

Props

prop default type
url string
params {} object
method "get" string
data {} object
options {} object
onSuccess void
onError void

Example

import { EasyFetch } from "react-easy-fetch";

const App = () => {
  const handleSuccess = (data) => console.log(data);
  const handleError = (error) => console.log(error);

  const Posts = (props) => {
    console.log(props.response);
    return <div>{props.isLoading && "Loading..."}</div>;
  };

  return (
    <EasyFetch
      url="https://jsonplaceholder.typicode.com/posts"
      method="post"
      params={{ posts: 1 }}
      data={{ post: 1, user: 2 }}
      options={{
        headers: { "X-Custom-Header": "value" },
      }}
      onSuccess={(data) => {
        console.log("onSuccess");
        handleSuccess(data);
      }}
      onError={(error) => {
        console.log("onError");
        handleError(error);
      }}
    >
      <Posts />
    </EasyFetch>
  );
};

Dependencies (1)

Dev Dependencies (8)

Package Sidebar

Install

npm i react-easy-fetch

Weekly Downloads

0

Version

1.1.1

License

MIT

Unpacked Size

7 kB

Total Files

13

Last publish

Collaborators

  • skorotkiewicz