1.0.5 • Published 6 years ago

@use-hooks/image-size v1.0.5

Weekly downloads
189
License
MIT
Repository
github
Last release
6 years ago

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.

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago