1.1.1 • Published 4 years ago

useelementwidth v1.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

useElementWidth

Pass an element ref that you’d like to observe. Its changing width is returned.

Example:

const Element = () => {
  const ref = useRef()
  const width = useElementWidth(ref)

  const classNames = width > 300 ?  styles.wide : ''

  return (
    <div ref={ref} className={`${styles.el} ${classNames}`} />
  )
}
.el {
  width: 100%;
  display: flex;
  flex-direction: column;
}

.wide {
  flex-direction: row;
}

Read the blog post

1.1.1

4 years ago

1.1.0

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago