O
O
Oleg2019-04-17 10:44:31
React
Oleg, 2019-04-17 10:44:31

How to get the height of a React component from another component?

Subject. There are two components that are in completely different places. I need to get the height value of another component inside one component. How to do it?
Right now I'm writing a custom hook that, when called, would pass an ID selector and return the height of the component with that ID. But I ran into a problem that in custom components the id attribute is treated as a prop, so it is not displayed in the DOM.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Spirin, 2019-04-17
@rockon404

Now I'm writing a custom hook that would pass an ID selector when called,

A hook is not needed for such an operation. In a good way, you should get the ref of the target element, and not look for it in the DOM using a selector.
Write a value to the store or state of the common parent.
Because the id should be thrown into the base components, but this is not necessary for solving your problem.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question