use-image-options
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

useImageOptions React Hook

Custom React Hook for loading images based on fetch API. It accepts image url and options and returns HTMLImageElement. Useful for canvas application like react-konva.

Install

npm install use-image-options

Usage

import React from "react";
import { Image } from "react-konva";
import { useImageOptions, IOptions } from "use-image-options";

const url = "https://someimageurl";

function ExampleUsage() {
  const options: IOptions = {
    headers: {
      "Cache-Control": "no-cache",
    },
    mode: "cors",
    cache: "no-cache",
  };
  const [image, status] = useImageOptions(url, options);

  // status can be "loading", "loaded" or "failed"
  return <Image image={image} />;
}

License

MIT

Package Sidebar

Install

npm i use-image-options

Weekly Downloads

4

Version

1.0.5

License

MIT

Unpacked Size

4.44 kB

Total Files

5

Last publish

Collaborators

  • vvn050