npm

Ready to take your JavaScript development to the next level? Meet npm Enterprise - the ultimate in enterprise JavaScript.Learn more »

use-image

1.0.3 • Public • Published

useImage React Hook

Custom React Hook for loading images.

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);
 
  // "image" will DOM image element or undefined
 
  return (
    <Image image={image} />
  );
}
 
function ComplexApp() {
  // set crossOrigin of image as second argument
  const [image, status] = useImage(url, 'Anonymous');
 
  // status can be "loading", "loaded" or "failed"
 
  return (
    <Image image={image} />
  );
}

License

MIT

install

npm i use-image

Downloadsweekly downloads

600

version

1.0.3

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability