1.3.0 • Published 2 years ago

rsrc v1.3.0

Weekly downloads
13
License
MIT
Repository
github
Last release
2 years ago

Logo

Rsrc

ci version license gzip size

A collection of components designed to simplify fetch state in React.

Docs

Getting Started

yarn add rsrc

Usage

import React from "react";
import { Resource } from "rsrc";

export default (props) => {
  const { id } = props;
  const url = `/todos/${id}`;

  return (
    <Resource
      url={url}
      maxAge={60}
      actions={{
        remove: () => ({
          options: {
            method: "DELETE",
          },
          invalidates: ["/todos"],
        }),
      }}
    >
      {({ state, actions }) => {
        if (!state.fulfilled) return null;

        const todo = state.value;

        const handleClick = () => {
          actions
            .remove()
            .then((value) => {
              /* */
            })
            .catch((error) => {
              /* */
            });
        };

        return (
          <div>
            <h1>{todo.name}</h1>
            <p>{todo.description}</p>
            <button onClick={handleClick}>×</button>
          </div>
        );
      }}
    </Resource>
  );
};

Related

1.3.0

2 years ago

1.2.0

3 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago