A
A
Alex Krynytskyi2021-01-23 12:59:43
React
Alex Krynytskyi, 2021-01-23 12:59:43

How to set block height based on neighboring block in ReactJS?

<div style={{height:400}}></div>
  <div style={{height:someHeight}}></div>


I want the bottom block to get the same height as the top block when rendering. And it varies depending on the amount of text.
How can I get and pass parameters ?
I tried to get the height through ref and pass it to the next one, but it swears ((

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir, 2021-01-23
@NEOmanceR

const el = React.createRef();
const [height, setH] = useState();

useEffect(() => setH(el.current.style.height));

<div ref={el} />
<div style={{height: height}}/>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question