get height component react

Solutions on MaxInterview for get height component react by the best coders in the world

showing results for - "get height component react"
Freddie
06 Apr 2018
1import React, { useState, useEffect, useRef } from 'react'
2
3export default () => {
4  const [height, setHeight] = useState(0)
5  const ref = useRef(null)
6
7  useEffect(() => {
8    setHeight(ref.current.clientHeight)
9  })
10
11  return (
12    <div ref={ref}>
13      {height}
14    </div>
15  )
16}
17