Access a generator function from within a component.
const generator = useGenerator(generatorKey) Copy
const generator = useGenerator(generatorKey)
The generator is an async function that process and returns data required by your components, such as geometry for a mesh.
const [geometry, setGeometry] = useState<BufferGeometry | null>(null)useEffect(() => { if (generator) { generator(id).then(response => { if (response) { const bufferGeometry = unpackBufferGeometry(response) setGeometry(prev => { if (prev) prev.dispose() return bufferGeometry }) } else { setGeometry(null) } }) }}, [generator, id])if (!geometry) return nullreturn ( <mesh geometry={geometry}> <meshBasicMaterial /> </mesh>) Copy
const [geometry, setGeometry] = useState<BufferGeometry | null>(null)useEffect(() => { if (generator) { generator(id).then(response => { if (response) { const bufferGeometry = unpackBufferGeometry(response) setGeometry(prev => { if (prev) prev.dispose() return bufferGeometry }) } else { setGeometry(null) } }) }}, [generator, id])if (!geometry) return nullreturn ( <mesh geometry={geometry}> <meshBasicMaterial /> </mesh>)
Generators
Access a generator function from within a component.
Example
Remarks
The generator is an async function that process and returns data required by your components, such as geometry for a mesh.
Example
See
Generators