Package Exports
- use-image
- use-image/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (use-image) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
useImage React Hook
Custom React Hook for loading images. It loads passed url and creates DOM image with such src.
Useful for canvas application like react-konva.
Install
npm install use-imageUsage
import React from 'react';
import { Image } from 'react-konva';
import useImage from 'use-image';
const url = 'https://konvajs.github.io/assets/yoda.jpg';
function SimpleApp() {
const [image] = useImage(url);
// "image" will be DOM image element or undefined
return (
<Image image={image} />
);
}
function ComplexApp() {
// set crossOrigin of image as second argument, set referrerpolicy as third argument
const [image, status] = useImage(url, 'anonymous', 'origin');
// status can be "loading", "loaded" or "failed"
return (
<Image image={image} />
);
}License
MIT