forked from rajun/ar-test
feat: add hook that waits for model-viewer
This commit is contained in:
parent
20edecf598
commit
1de8233667
18
app/hooks/use-model-viewer-ready.ts
Normal file
18
app/hooks/use-model-viewer-ready.ts
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import { useEffect, useState } from 'react';
|
||||||
|
|
||||||
|
// <model-viewer> is loaded globally from root.tsx; this waits until the custom element is defined
|
||||||
|
export function useModelViewerReady() {
|
||||||
|
const [ready, setReady] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
let cancelled = false;
|
||||||
|
customElements.whenDefined('model-viewer').then(() => {
|
||||||
|
if (!cancelled) setReady(true);
|
||||||
|
});
|
||||||
|
return () => {
|
||||||
|
cancelled = true;
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return ready;
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user