1.3.0 • Published 4 days ago

react-roi v1.3.0

Weekly downloads
-
License
-
Repository
-
Last release
4 days ago

react-roi

NPM version npm download

React library to draw, move and resize rectangles.

Installation

npm i react-roi

Usage

Components:

import { RoiComponent } from 'react-roi';

function MyComponent() {
  return (
    <RoiComponent>
      <div style={{ width: '500px', height: '5S00px' }} />
    </RoiComponent>
  );
}

Images:

import { useContext, useEffect, useState } from 'react';
import { decode, Image } from 'image-js';
import { RoiComponent } from 'react-roi';
const [image, setImage] = useState(null);

useEffect(() => {
  const fetchImage = async (url) => {
    const response = await fetch(url.pathname);
    const buffer = await response.arrayBuffer();
    return decode(new Uint8Array(buffer));
  };
  fetchImage('your/url')
    .then((image) => setImage(image))
    .catch((error) => console.warn(error));
}, []);

function MyComponent() {
  return image ? (
    <RoiComponent image={image} options={{ width: 700, height: 500 }} />
  ) : null;
}

To access the state of the component, you need to render the RoiProvider at the top level of the required component. By doing so, any components wrapped within the RoiProvider will have access to the state provided by the context.

import { RoiProvider } from 'react-roi';

export default function App() {
  return (
    <RoiProvider>
      <MyComponent />
    </RoiProvider>
  );
}
1.3.0

4 days ago

1.2.0

1 month ago

1.1.0

2 months ago

1.0.1

2 months ago

1.0.0

2 months ago

0.16.1

2 months ago

0.16.0

2 months ago

0.15.0

2 months ago

0.14.0

3 months ago

0.13.1

3 months ago

0.13.0

3 months ago

0.12.1

3 months ago

0.12.0

4 months ago

0.10.0

4 months ago

0.11.0

4 months ago

0.10.1

4 months ago

0.9.0

4 months ago

0.8.1

4 months ago

0.8.0

5 months ago

0.7.0

5 months ago

0.5.0

6 months ago

0.6.1

5 months ago

0.6.0

6 months ago

0.3.0

8 months ago

0.2.0

9 months ago

0.1.0

10 months ago

0.0.2

11 months ago