videx-3d
Version:
React 3D component library designed for sub surface visualizations in the browser
44 lines (43 loc) • 1.08 kB
TypeScript
/**
* Access a generator function from within a component.
*
* @example
* const generator = useGenerator(generatorKey)
*
* @remarks
* The generator is an async function that process and returns data required
* by your components, such as geometry for a mesh.
*
* @example
*
* 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 null
*
* return (
* <mesh geometry={geometry}>
* <meshBasicMaterial />
* </mesh>
* )
*
* @see [Generators](/videx-3d/docs/documents/generators.html)
*
* @group Hooks
*/
export declare const useGenerator: <T>(generator: string) => ((...args: any[]) => Promise<T>) | (() => Promise<null>);