1.1.1 • Published 2 years ago

react-easy-fetch v1.1.1

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

react-easy-fetch

Easy React component wrapper for axios

Install

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

Props

propdefaulttype
urlstring
params{}object
method"get"string
data{}object
options{}object
onSuccessvoid
onErrorvoid

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>
  );
};
1.1.1

2 years ago

1.1.0

2 years ago

1.0.1

4 years ago

1.0.0

4 years ago