react-native-filament
Version:
A real-time physically based 3D rendering engine for React Native
17 lines (14 loc) • 397 B
text/typescript
import { useEffect } from 'react'
import { Entity, Scene } from '../types'
/**
* A hook that "on mount" adds the entity to the scene, and "on unmount" removes it.
*/
export function useEntityInScene(scene: Scene, entity?: Entity) {
useEffect(() => {
if (entity == null) return
scene.addEntity(entity)
return () => {
scene.removeEntity(entity)
}
}, [entity, scene])
}