@simpleimg/uploader-react
v1.0.15
Published
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.
Downloads
24
Readme
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
yarn add @simpleimg/uploader-react
or
npm install @simpleimg/uploader-react
Documentation
You can find the documentation for the Uploader React Component here.
Quick Usage
This component can returns null
, string
, Array<string>
, ImageObject
or Array<ImageObject>
.
Quick Usage - Single Image - string
- It will returns
string
if value isstring
andmax = 1 | undefined
. - If no value, an empty string will be returned.
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 ifmax > 1
. - If you set
max=2
and provide 3 images, it will returns 2 images. - If no value, an empty array will be returned.
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
if value is likeobject
,ImageObject
,null
orundefined
, andmax = 1 | undefined
. - If no value,
null
will be returned.
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 likeobject
, or ifmax > 1
. - If you set
max=2
and provide 3 images, it will returns 2 images.
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
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 [email protected]