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
.
Open image demo
Install
npm install use-image
Usage
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);
return (
<Image image={image} />
);
}
function ComplexApp() {
const [image, status] = useImage(url, 'anonymous', 'origin');
return (
<Image image={image} />
);
}
License
MIT