mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-04 17:38:10 +00:00
use useEffect
This commit is contained in:
1 parent
b657abe90d
commit
06a089c44b
1 file changed
+11
-5
@@ -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>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user