1.6.0 • Published 3 years ago

@wbe/use-responsive-image-data v1.6.0

Weekly downloads
271
License
MIT
Repository
github
Last release
3 years ago

@wbe/use-responsive-image-data

This hook allow to get image object whose width is closest to the value provided in px.

npm.io npm.io npm.io npm.io npm.io

Installation

$ npm install -s @wbe/use-responsive-image-data

How to use

Basic usage:

import useResponsiveImageData, { IImage } from "@wbe/use-responsive-image-data";

const thumbs: IImage[] = [
  {
    url: "my/image/1.jpg",
    width: 640,
    height: 480
  },
  {
    url: "my/image/2.jpg",
    width: 1024,
    height: 800
  }
];

const App = () => {
  // will return the first object of thumbs array
  // (640 is the up closest to 500)
  const responsiveImageData: IImage = useResponsiveImageData(thumbs, 500);

  // ...
};

Parameters

pImages: IImage[], pWidth?: number

paramstypedescriptiondefault value
pImagesIImage[]array of image object/
pWidthnumberwith limit of image object we need (px)window.innerWidth

Returned

The hook returns an IImage object:

{
  "url": number,
  "width": number,
  "height": number
}
1.6.0

3 years ago

1.5.0

3 years ago

1.4.2

4 years ago

1.4.2-alpha.0

4 years ago

1.4.1

4 years ago

1.4.0-alpha.0

4 years ago

1.4.0-alpha.1

4 years ago

1.4.0

4 years ago

1.3.1-alpha.1

4 years ago

1.3.0

4 years ago

1.2.0

4 years ago

1.1.0-alpha.0

4 years ago

1.0.0-alpha.0

4 years ago

0.0.30

4 years ago

0.0.29

4 years ago

0.0.28

4 years ago

0.0.27

4 years ago

0.0.25

4 years ago

0.0.26

4 years ago

0.0.24

4 years ago