Reputation: 25
How to get an image's width and height after scaling & rendering the react component
Upvotes: 1
Views: 830
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