1.0.16 • Published 4 years ago

rt-image v1.0.16

Weekly downloads
8
License
MIT
Repository
github
Last release
4 years ago

React-Image

basic image preview component with headers

react node-current NPM Build Status NPM Downloads

Usage

npm install rt-image

# yarn add rt-image

examples

import React, { useEffect, useState } from 'react';
import ReactDOM from 'react-dom';

import Image from 'rt-image';

const images = [
  'https://image.shutterstock.com/image-photo/white-transparent-leaf-on-mirror-260nw-1029171697.jpg',
  'https://images.pexels.com/users/avatars/454176/naturally-beautiful-inspiration-893.jpeg?w=256&h=256&fit=crop&crop=faces&auto=compress',
  'https://images.pexels.com/photos/1133957/pexels-photo-1133957.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500',
  'https://images.pexels.com/photos/556666/pexels-photo-556666.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500',
];

const App = () => {
  const [src, setSrc] = useState(images[0]);
  useEffect(() => { setTimeout(() => setSrc(images[1])); }, [src]);

  return (
    <div className="App">
      <Image style={{ marginRight: '5px' }} src={src} errorMessage="some thing bad happen" />
      <Image style={{ marginRight: '5px' }} src={images[2]} errorMessage="load image error" />
      <Image src={images[3]} />
    </div>
  );
};

ReactDOM.render(<App />, document.getElementById('root'));

request image width headers

<Image src="https://xxx.images.com/11111" headers={{ Authorization: 'xxx' }} />

custom image loader

<Image src="https://xxx.images.com/11111" loader={() => <div>loading...</div>} />

custom error displayer

<Image src="https://xxx.images.com/11111" renderError={() => <div>some error happens</div>} />

example

Properties

typedescriptionrequired
srcstringimage urltrue
widthnumberimage component widthfalse
heightnumberimage component height, default same with widthfalse
classNamestringcustom className to image componentfalse
styleReact.CSSPropertiesstylesfalse
descriptionstringused as image alt currentlyfalse
errorMessagestringcustom error messagefalse
headersobjectrequest headersfalse
loader() => React.ReactNode / nullcustom image loaderfalse
renderError() => React.ReactNode / nullcustom error displayerfalse

License

MIT © Rynxiao/react-image

1.0.16

4 years ago

1.0.15

4 years ago

1.0.14

4 years ago

1.0.13

4 years ago

1.0.12

4 years ago

1.0.11

4 years ago

1.0.10

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago