Last active
August 19, 2021 18:51
-
-
Save rileybathurst/629278026727c9d7a8150df8def9ae3c to your computer and use it in GitHub Desktop.
Set the height from one element due to another in react
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState, useEffect, useRef } from 'react'; | |
function Example() { | |
const [jump, setJump] = useState(0); | |
useEffect(() => { | |
const set = useRef(); | |
setJump(set.current.clientHeight); | |
}); | |
const sectionStyle = { | |
background: "palegreen", | |
height: {jump}.jump | |
} | |
const twenty = { | |
height: "20rem" | |
} | |
return ( | |
<div> | |
<div ref={set} style={twenty}> | |
Set Height | |
</div> | |
<section style={sectionStyle}>🦄</section> | |
</div> | |
); | |
} | |
// markup | |
const IndexPage = () => { | |
return ( | |
<main> | |
<title>Home Page</title> | |
<Example /> | |
</main> | |
) | |
} | |
export default IndexPage; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this is built in Gatsby but thats not really the point