Chiranjeevi M
Chiranjeevi M

Reputation: 25

How to get an image's width and height after scaling & rendering the react component

How to get an image's width and height after scaling & rendering the react component

Upvotes: 1

Views: 830

Answers (1)

Matthew Kwong
Matthew Kwong

Reputation: 2937

// equivalent to componentDidMount
useEffect(() => {
  const height = document.getElementById("myImg").clientHeight
  const width =document.getElementById("myImg").clientWidth
  // update the state
}, [])

I'm not sure why do you have to get the width and height after rendering, it doesn't sound like to be a good thing.

Upvotes: 1

Related Questions