use useEffect

This commit is contained in:
wil committed 2024-03-25 10:53:59 -04:00
1 parent b657abe90d
commit 06a089c44b
1 file changed
+11 -5
+11 -5
View File
@@ -1,6 +1,6 @@
import {
ReactNode,
useLayoutEffect,
useEffect,
useRef,
} from "react";
import { EngineContext } from "./EngineContext";
@@ -14,17 +14,23 @@ interface Props{
export const EngineProvider = ({ children }: Props)=>{
const editorRef = useRef<Editor | null>(null);
useLayoutEffect(() => {
useEffect(() => {
//componentDidMount
if (editorRef.current == null) {
if (editorRef.current !== null ) {
console.warn('Editor Engine already exist');
}else if (document.getElementById("video-scene") === null){
console.error('Editor Engine need a target cavas with the id "video-scene"');
}else{
editorRef.current = new Editor();
editorRef.current.initialize();
}
}, []);
return(
<EngineContext.Provider value={editorRef.current}>
{children}
</EngineContext.Provider>
);
}
}