0.1.5 • Published 7 years ago

react-fetch-as v0.1.5

Weekly downloads
3
License
MIT
Repository
github
Last release
7 years ago

React Fetch As Component

Install

npm install --save react-fetch-as

Example

After response, children component (<Slider/>) will be rendered with "photos" prop, which will contain data from response.

import React, { Component } from 'react';
import Fetch from 'react-fetch-as';

class FetcherExample extends Component {
  render() {
    return (
      <Fetch from="http://example.org/photos" as="photos">
        <Slider/>
      </Fetch>
    );
  }
}

You can nested <Fetch/> components. <Slider/> receive "photos" and "images" prop.

import React, { Component } from 'react';
import Fetch from 'react-fetch-as';

class NestedExample extends Component {
  render() {
    return (
      <Fetch from="http://example.org/photos" as="photos">
        <Fetch from="http://example.org/images" as="images">
          <Slider/>
        </Fetch>
      </Fetch>
    );
  }
}

Props

NameDescriptionIs requiredDefault
fromURL of the resource you want to fetch.yes-
asName of the prop, which will be passed to the children component.nodata
optionsFetch options (https://developer.mozilla.org/en-US/docs/Web/API/GlobalFetch/fetch#Parameters)no{}
toJsonIf true response will be parsed to object.notrue
spinnerReact component or string. Will be displayed while loading.nonull
onErrorCallback on catch error.no-
onSuccessCallback on success.no-
0.1.5

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago