@use-hooks/image-size

1.0.5 • Public • Published

react-hooks-image-size

NPM version npm download Build Status

Custom React Hooks for image natural size.

Install

Note: Make sure that you have installed the correct version of react(>= v16.8.0) and react-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>
  );
}

Live Show

Development

Node >= v8 LTS

  • Clone the project to local disk
  • npm install
  • npm start

License

MIT

Generated by create-react-hooks.

Readme

Keywords

Package Sidebar

Install

npm i @use-hooks/image-size

Weekly Downloads

89

Version

1.0.5

License

MIT

Unpacked Size

6.88 kB

Total Files

4

Last publish

Collaborators

  • int64ago