npm package: @simpleimg/uploader-react
Description: This component helps you integrate Simple Image Cloud Uploader Widget with your React App. It allows users to upload images, manage and edit them from their devices, without any backend code.
Author: Felipe Rohde
Latest version: 1.0.22

## Simple Image Cloud - Uploader Widget for React

This component helps you integrate Simple Image Cloud Uploader Widget with your React App.
It allows users to upload images, manage and edit them from their devices, without any backend code.

* [Install](#install)
* [Documentation](#documentation)
* [Quick Usage](#quick-usage)
	* [Single Image - `string`](#quick-usage---single-image---string)
	* [Multiple Image - `Array<string>`](#quick-usage---multiple-image---arraystring)
	* [Single Image - `ImageObject`](#quick-usage---single-image---imageobject)
	* [Multiple Image - `Array<ImageObject>`](#quick-usage---multiple-image---arrayimageobject)
* [Image Object](#image-object)
* [Feedback](#feedback)

## Install

```
yarn add @simpleimg/uploader-react
```
or
```
npm install @simpleimg/uploader-react
```

## Documentation

You can find the documentation for the Uploader React Component [here](https://simpleimagecloud.com/docs/uploader-react).

## Quick Usage

This component can returns `null`, `string`, `Array<string>`, [`ImageObject`](#image-object) or [`Array<ImageObject>`](#image-object).

## Quick Usage - Single Image - `string`
* It will returns `string` if value is `string` and `max =  1 | undefined`.
* If no value, an empty string will be returned.

```jsx
import Uploader from '@simpleimg/uploader-react';
import {
    useCallback,
	useState
} from 'react';

export default () => {
	const [
		value,
		setValue
	] = useState('https://demo.simpleimg.io/image-1.jpg');

	/*
		sample returned value:
		https://demo.simpleimg.io/image-1.jpg
	*/
                                    
    return (
        <Uploader apiKey="[YOUR_API_KEY]"
			onChange={setValue}
            value={value}/>
    );
};
```

## Quick Usage - Multiple Image - `Array<string>`
* It will returns `Array<string>` if value is like array, or if `max > 1`.
* If you set `max=2` and provide 3 images, it will returns 2 images.
* If no value, an empty array will be returned.

```jsx
import Uploader from '@simpleimg/uploader-react';
import {
    useCallback,
	useState
} from 'react';

export default () => {
	const [
		value,
		setValue
	] = useState([
		'https://demo.simpleimg.io/image-1.jpg',
		'https://demo.simpleimg.io/image-2.jpg'
	]);

	/*
		sample returned value:
		[
			'https://demo.simpleimg.io/image-1.jpg',
			'https://demo.simpleimg.io/image-2.jpg'
		]
	*/
                                    
    return (
        <Uploader apiKey="[YOUR_API_KEY]"
			max={2}
			onChange={setValue}
            value={value}/>
    );
};
```

## Quick Usage - Single Image - `ImageObject`
* It will returns [`ImageObject`](#image-object) if value is like `object`, [`ImageObject`](#image-object), `null` or `undefined`, and `max =  1 | undefined`.
* If no value, `null` will be returned.

```jsx
import Uploader from '@simpleimg/uploader-react';
import {
    useCallback,
	useState
} from 'react';

export default () => {
	const [
		value,
		setValue
	] = useState({
		url: 'https://demo.simpleimg.io/image-1.jpg'
	});

	/*
		sample returned value:
		{
			blurHash: string;
			colors: [{
				count: number;
				hex: string;
				name: string;
				type: string;
			}];
			contentLength: number;
			contentType: string;
			createdAt: number;
			extension: string;
			height: number;
			id: string;
			putAt: number;
			updatedAt: number;
			version: number;
			width: number;
			url: string;
		}
	*/
                                    
    return (
        <Uploader apiKey="[YOUR_API_KEY]"
			onChange={setValue}
            value={value}/>
    );
};
```

## Quick Usage - Multiple Image - `Array<ImageObject>`
* It will returns `Array<ImageObject>` if value is an empty array or with all elements like `object`, or if `max > 1`.
* If you set `max=2` and provide 3 images, it will returns 2 images.

```jsx
import Uploader from '@simpleimg/uploader-react';
import {
    useCallback,
	useState
} from 'react';

export default () => {
	const [
		value,
		setValue
	] = useState([{
		url: 'https://demo.simpleimg.io/image-1.jpg'
	}, {
		url: 'https://demo.simpleimg.io/image-2.jpg'
	}]);

	/*
		sample returned value:
		[{
			blurHash: string;
			colors: [{
				count: number;
				hex: string;
				name: string;
				type: string;
			}];
			contentLength: number;
			contentType: string;
			createdAt: number;
			extension: string;
			height: number;
			id: string;
			putAt: number;
			updatedAt: number;
			version: number;
			width: number;
			url: string;
		}, {
			blurHash: string;
			colors: [{
				count: number;
				hex: string;
				name: string;
				type: string;
			}];
			contentLength: number;
			contentType: string;
			createdAt: number;
			extension: string;
			height: number;
			id: string;
			putAt: number;
			updatedAt: number;
			version: number;
			width: number;
			url: string;
		}]
	*/
                                    
    return (
        <Uploader apiKey="[YOUR_API_KEY]"
			max={2}
			onChange={setValue}
            value={value}/>
    );
};
```

## Image Object

```ts
	interface ImageObject {
		// The image's blurHash: see more at https://blurha.sh/
		blurHash: string;
		// The image's dominant colors
		colors: Array<{
			count: number;
			hex: string;
			name: string;
			type: string;
		}>;
		// The image's content length
		contentLength: number;
		// The image's content type
		contentType: string;
		// The image's first creation date
		createdAt: number;
		// The image's extension
		extension: string;
		// The image's height
		height: number;
		// The image's id
		id: string;
		// The image's last creation date (it will changes if you upload same image)
		putAt: number;
		// The image's last update date
		updatedAt: number;
		// The image's version
		version: number;
		// The image's width
		width: number;
		// The image's url
		url: string;
	}

```

## Feedback

We want to hear your issue reports and feature requests at support@simpleimagecloud.com