Skip to content

Commit

Permalink
Merge pull request #261 from dennemark/renderHtmlAfter
Browse files Browse the repository at this point in the history
Use useAfterRender instead of useBeforeRender for Html
  • Loading branch information
brianzinn authored Nov 17, 2022
2 parents 7f0eac1 + c9e523c commit f8b331c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/react-babylonjs/src/customComponents/Html.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import React, {
// import { unmountComponentAtNode } from 'react-dom'
import { createRoot } from 'react-dom/client'
import { FiberAbstractMeshProps, FiberAbstractMeshPropsCtor } from '../generatedProps'
import { useBeforeRender } from '../hooks/render'
import { useAfterRender } from '../hooks/render'
import { useScene } from '../hooks/scene'

function defaultCalculatePosition(el: AbstractMesh, camera: Camera) {
Expand Down Expand Up @@ -288,7 +288,7 @@ const Html = forwardRef(

const visible = useRef(true)

useBeforeRender(() => {
useAfterRender(() => {
const camera = scene?.activeCamera

if (camera && group.current) {
Expand Down
5 changes: 3 additions & 2 deletions packages/react-babylonjs/src/hooks/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ export const useAfterRender = (
callback: OnFrameRenderFn,
mask?: number,
insertFirst?: boolean,
callOnce?: boolean
callOnce?: boolean,
deps: React.DependencyList = []
): void => {
const { scene } = useContext(SceneContext)

Expand All @@ -79,5 +80,5 @@ export const useAfterRender = (
scene.onAfterRenderObservable.remove(sceneObserver)
}
}
})
}, [scene, ...deps])
}

0 comments on commit f8b331c

Please sign in to comment.