@ue-too/board-pixi-react-integration / index / useInitializePixiApp
函式: useInitializePixiApp()
useInitializePixiApp<
T>(option,initFunction,className?):object
定義於: board-pixi-react-integration/src/hooks/pixi/initialization.ts:33
Initializes a Pixi application into a container element and tears it down on unmount. Attach the returned containerRef to a wrapping element; a fresh <canvas> is created inside it for each initialization.
The design below prevents a class of WebGL-context bugs that hard-freeze the GPU process on some drivers (notably Linux/Mesa):
- Init runs once per mount. Callers routinely pass an inline
optionobject andinitFunctionclosure, so keying the effect on them would re-initialize Pixi on every render — destroying and recreating the GL context on the same canvas, which collides with the in-flight renderer and wedges the GPU. The latest values are read from refs instead, so the effect depends only on the stablesetResult. - Init/teardown are serialized through a promise chain, so two initializations never overlap (e.g. React StrictMode's mount→unmount→ mount in dev, or a fast remount). The previous context is fully destroyed before the next one is created.
- A fresh
<canvas>per init. Pixi callsWEBGL_lose_contextwhen the renderer is destroyed; a canvas whose context was lost cannot be reinitialized, so each init gets a brand-new element and the old one is detached on teardown (removeView).
型別參數
T
T extends InitAppOptions = InitAppOptions
參數
option
Partial<T>
initFunction
(canvas, option) => Promise<BaseAppComponents>
className?
string
回傳
object
containerRef
containerRef:
RefObject<HTMLDivElement|null>