New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

react-api-fetch-component

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

react-api-fetch-component

A react fetch component. Usefull for consuming API.

latest
Source
npmnpm
Version
0.1.3
Version published
Maintainers
1
Created
Source

react-api-fetch-component

A react component to fetch data from your favorite API.

Installation

npm i --save react-api-fetch-component

Usage

Don't forget to see the example folder, it contains a complete example of this component, with user registration / login / logout example.

First, include the provider at the root of your app:

    import {FetchProvider} from "react-api-fetch-component";
    
    <FetchProvider
        baseUrl={'https://example.fr/api'}
        baseMode={"cors"}
        beforeRequest={(request) => {
            // Set the user auth token before each request for example
        }}
        onError={(error, request) => {
            // Common onError, call everytime an error append. Usefull for the refresh token.
        }
    >
        {...children}
    </FetchProvider>

Now, you can use the Fetch component where you want to make request:

    import {Fetch} from "react-api-fetch-component";
    
    <Fetch url={'/api/endpoint'} method={'GET'}>
        {({loading, error, data}) => {
            return (
                <div>{data.id}</div>
            );
        }}
    </Fetch>

You can see more example in the corresponding folder.

This project is open to contributions :)

FAQs

Package last updated on 11 May 2019

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