0.0.1 • Published 5 years ago

create-restful-hooks v0.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
5 years ago

create-restful-hooks

Usage

 import createRestfulHooks from 'create-restful-hooks';

createRestfulHooks.config({
  baseUrl: 'https://www.example.com/api',
});

const {
  useProducts,
  useProduct,
} = createRestfulHooks('products');

const ProductPage = ({ params }) => {
  const [product, loading, error] = useProduct(params.id); // request to https://www.example.com/api/products/:id

  if (loading) return <p>Loading</p>;
  if (error) return <pre>{JSON.stringify(error, null, 2)}</pre>;

  return (
    <div>
      <h1>{product.name}</h1>
      <h1>{product.description}</h1>
    </div>
  );
};