0.0.0 • Published 5 years ago

@codesend/react-fetch v0.0.0

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

react-fetch

A component for fetching resources that also provides error and loading states.

Installation

  yarn add @codesend/react-fetch

Examples

import Fetch from "@codesend/react-fetch";
import React from "react";

function Todo({ completed, title }) {
  return (
    <div>
      <input defaultChecked={completed} type="checkbox" />
      <label>{title}</label>
    </div>
  );
}

function TodoList() {
  return (
    <Fetch input="https://jsonplaceholder.typicode.com/todos">
      {({ data, error, loading }) => {
        if (error) return `Error! ${error.message}`;
        if (loading) return "Loading...";

        return data.map(todo => (
          <Todo completed={todo.completed} key={todo.id} title={todo.title} />
        ));
      }}
    </Fetch>
  );
}