2.2.5 • Published 6 years ago

react-fetchino v2.2.5

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

react-fetchino

Build Status codecov semantic-release

A tiny React component to fetch HTTP requests. It requires React >= 16.3.0

Getting started

$ # With npm
$ npm install --save react-fetchino
$ # Or yarn
$ yarn add react-fetchino

Props

NameTypeRequiredDescription
urlstringtrueURL of the resource to fetch
optionsobjectfalseOverrides the default options {}
renderfunctionfalseCan be used instead of children

Code examples

import React, { Component, Fragment } from 'react';
import Fetchino from 'react-fetchino';

// Pattern: Function as Child Component
// Props: required

class App extends Component {
  render() {
    const url = 'https://swapi.co/api/planets/1/';
    return (
      <Fetchino url={url}>
        {({ loading, error, data }) => (
          <Fragment>
            { loading && <LoadingComponent /> }
            { error && <ErrorComponent message={error} /> }
            { data && <PlanetComponent data={data} /> }
          </Fragment>
        )}
      </Fetchino>
    );
  }
}

// Pattern: Render Props
// Props: all

class App extends Component {
  render() {
    const url = 'https://jsonplaceholder.typicode.com/posts';
    const options = {
      method: 'POST',
      headers: {
        'Content-type': 'application/json'
      },
      body: {
        test: 'Test',
      }
    };
    return (
      <Fetchino
        url={url}
        options={options}
        render={({ loading, error, data }) => (
          <Fragment>
            {loading && <LoadingComponent />}
            {error && <ErrorComponent message={error} />}
            {data && <PostComponent data={data} />}
          </Fragment>
        )}
      />
    );
  }
}

Note: if both render and children are functions, render will be ignored.

Demo

Click here to open the live demo.

Tasks

Development

$ npm run test:watch
$ npm run build

Tests & Coverage

$ npm run test
$ npm run test:coverage

Missing

2.2.5

6 years ago

2.2.4

6 years ago

2.2.3

6 years ago

2.2.2

6 years ago

2.2.1

6 years ago

2.2.0

6 years ago

2.1.1

6 years ago

2.1.0

6 years ago

2.0.0

6 years ago

1.5.0

6 years ago

1.4.0

6 years ago

1.3.0

6 years ago

1.2.0

6 years ago

1.1.0

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago