Skip to content

React component that integrate the fetch api inspired by apollo-client

License

Notifications You must be signed in to change notification settings

Wizyma/react-fetch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

react-fetch

Build Status codecov

React component that integrate the fetch api inspired by apollo-client

Usage

// by default the GET method is used
import React, { Component, Fragment } from 'react'
import Fetch from 'react-fetch'
import MyErrorComponent from './error-component'
import LoadingComponent from './loading'

class MyComponent extends Component {
  render() {
    return(
      <Fragment>
        <h1>My Fetch component will be a child who will load asynchronously the data !</h1>
        <Fetch url='https://jsonplaceholder.typicode.com/posts'>
          {({ error, data, loading }) => {
            if(error) return <MyErrorComponent />
            if(loading) return <LoadingComponent />

            if(data) {
              return (
                data.map(({ id, title, body }) => (
                  <div key={id}>
                    <h1>{title}</h1>
                    <p>{body}</p>
                  </div>
                ))
              )
            }
          }}
        </Fetch>
      </Fragment>
    )
  }
}

You can use all the http verbs. The Fetch component has optionals parameters such as credentials and headers.

Do not hesitate to make a pull request or make some suggestions. PR are welcome ❤️

About

React component that integrate the fetch api inspired by apollo-client

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published