react-konva-image

0.0.1 • Public • Published

useKonvaImage React Hook

A custom React Hook for loading react konva image.

Installation

npm install react-konva-image

Importing

import useKonvaImage from 'react-konva-image';

Usage

import React from 'react';
import { Image } from 'react-konva';
import useKonvaImage from 'react-konva-image';

const imgUrl = 'https://konvajs.org/assets/lion.png';

//Pass image as first argument to useKonvaImage hook
//It will return image DOM image element
export default App = () => {
  const [image] = useKonvaImage(imgUrl);

  return <Image image={image} />;
};

//Pass image as 1st argument & crossOrigin as 2nd argument to useKonvaImage hook
//It will return image DOM image element & status
//Status can be 'laoding', 'loaded', or 'failed'
export default App = () => {
  const [image, status] = useKonvaImage(imgUrl, 'Anonymous');

  return <Image image={image} />;
};

Package Sidebar

Install

npm i react-konva-image

Weekly Downloads

42

Version

0.0.1

License

ISC

Unpacked Size

2.41 kB

Total Files

3

Last publish

Collaborators

  • premsagar