1.0.5 • Published 6 years ago
@use-hooks/image-size v1.0.5
react-hooks-image-size
Custom React Hooks for image natural size.
Install
Note: Make sure that you have installed the correct version of
react(>= v16.8.0)
andreact-dom(>= v16.8.0)
.
npm
npm install --save @use-hooks/image-size
yarn
yarn add @use-hooks/image-size
API
Params
/**
* Params
* @param {string} url - The image url
*/
Returns
/**
* Returns
* @param {array} size - The image size [width, height]
*/
Usage
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 (
<div>
<h2>DEMO of <span style={{ color: '#F44336' }}>@use-hooks/image-size</span></h2>
<div>
<img src={url} width={100} height={100} alt="" />
<div>Natural size: {width} x {height}</div>
</div>
</div>
);
}
Development
Node >= v8 LTS
- Clone the project to local disk
npm install
npm start
License
MIT
Generated by create-react-hooks.