Skip to content
Discussion options

You must be logged in to vote

This seemed to lag behind each resize (resizing correctly, but one resize too late — race condition maybe?).

https://codesandbox.io/s/r3f-contact-shadow-forked-8bw74?file=/src/Image.js

Edit: It seems that your Image component is reliant on an image in the dom. I've added its props as dependencies in a useEffect hook and it will update in sync.

const { width, height, top, left } = primaryImage.getBoundingClientRect()

// There's a better way to do this, right?
const [scaleX, setScaleX] = useState()
const [scaleY, setScaleY] = useState()
const [posX, setPosX] = useState()
const [posY, setPosY] = useState()

useEffect(() => {
  setScaleX((width / window.innerWidth) * viewport.width)
  setScaleY

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@joakim-roos
Comment options

@CodyJasonBennett
Comment options

@CodyJasonBennett
Comment options

@joakim-roos
Comment options

Answer selected by joakim-roos
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants