Skip to content

Commit

Permalink
fix(useIntersect): call live callback (#1084)
Browse files Browse the repository at this point in the history
  • Loading branch information
CodyJasonBennett committed Oct 7, 2022
1 parent e7daabd commit 4376265
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/core/useIntersect.tsx
Expand Up @@ -5,6 +5,8 @@ export function useIntersect<T extends THREE.Object3D>(onChange: (visible: boole
const ref = React.useRef<T>(null!)
const check = React.useRef(false)
const temp = React.useRef(false)
const callback = React.useRef(onChange)
React.useLayoutEffect(() => void (callback.current = onChange), [onChange])
React.useEffect(() => {
const obj = ref.current
if (obj) {
Expand All @@ -18,7 +20,7 @@ export function useIntersect<T extends THREE.Object3D>(onChange: (visible: boole
obj.onBeforeRender = () => (check.current = true)
// Compare the check value against the temp value, if it differs set state
const unsub2 = addAfterEffect(() => {
if (check.current !== temp.current) onChange((temp.current = check.current))
if (check.current !== temp.current) callback.current?.((temp.current = check.current))
return true
})
return () => {
Expand Down

1 comment on commit 4376265

@vercel
Copy link

@vercel vercel bot commented on 4376265 Oct 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.