use-child-sizes
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

use-child-sizes

A React hook to get the sizes of child elements of the specified element.

NPM

Install

npm install use-child-sizes

Usage

import React from 'react'
import useChildSizes from 'use-child-sizes'
 
const Example = () => {
  const [ref, sizes] = useChildSizes<HTMLUListElement>()
  const maxHeight = sizes.reduce(
    (maxHeight, { height }) => (height > maxHeight ? height : maxHeight),
    0
  )
 
  return (
    <ul ref={ref} style={{ height: maxHeight }} className='...'>
      <li>
        <img src='...' />
      </li>
      <li>
        <img src='...' />
      </li>
      <li>
        <img src='...' />
      </li>
    </ul>
  )
}

IE?

Use ResizeObserver Polyfill.

License

MIT © Taro Hanamura

Readme

Keywords

none

Package Sidebar

Install

npm i use-child-sizes

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

20.3 kB

Total Files

9

Last publish

Collaborators

  • hanamura