Custom React Hooks for image natural size.
npm install @use-hooks/image-size[![NPM version][npm-image]][npm-url]
[![npm download][download-image]][download-url]
[![Build Status][travis-image]][travis-url]
Custom React Hooks for image natural size.
>Note: Make sure that you have installed the correct version of react(>= v16.8.0) and react-dom(>= v16.8.0).
``bash`
npm install --save @use-hooks/image-size
`bash`
yarn add @use-hooks/image-size
`js`
/**
* Params
* @param {string} url - The image url
*/
`js`
/**
* Returns
* @param {array} size - The image size [width, height]
*/
`js
import React from 'react';
import useImageSize from '@use-hooks/image-size';
export default function App() {
const url = 'https://cdn.int64ago.org/ogk39i54.png';
const [width, height] = useImageSize(url);
return (
`
> Node >= v8 LTS
- Clone the project to local disk
- npm installnpm start`
-
MIT
> Generated by create-react-hooks.
[npm-image]: https://img.shields.io/npm/v/@use-hooks/image-size.svg?style=flat-square
[npm-url]: https://npmjs.org/package/@use-hooks/image-size
[download-image]: https://img.shields.io/npm/dm/@use-hooks/image-size.svg?style=flat-square
[download-url]: https://npmjs.org/package/@use-hooks/image-size
[travis-url]: https://travis-ci.org/use-hooks/react-hooks-image-size
[travis-image]: https://img.shields.io/travis/use-hooks/react-hooks-image-size.svg?style=flat-square