Runs a one-time initialization function exactly once when the entity is first mounted.
Unlike useEffect, this never re-runs on refreshes — perfect for true setup that should survive structural changes.
This hook MUST be called at the top level of a component function — never inside loops, conditions, nested functions, or callbacks.
The call order of all hooks is strictly fixed across every refresh; reordering calls will corrupt internal state.
If the callback returns a function, it is called only on final entity destruction.
Multiple useInitialization calls stack — all run in declaration order.
Type Declaration
(init:()=>void| (()=>void)):void
Parameters
init: ()=>void| (()=>void)
One-time setup function — may return cleanup
Returns void
Example
useInitialization(() => { constbody = physicsEngine.createBody({ ... }); return () =>physicsEngine.destroyBody(body); // cleanup only on unmount });
Runs a one-time initialization function exactly once when the entity is first mounted.
Unlike
useEffect, this never re-runs on refreshes — perfect for true setup that should survive structural changes.This hook MUST be called at the top level of a component function — never inside loops, conditions, nested functions, or callbacks. The call order of all hooks is strictly fixed across every refresh; reordering calls will corrupt internal state.
If the callback returns a function, it is called only on final entity destruction.
Multiple
useInitializationcalls stack — all run in declaration order.