Skip to content
Work in progress. These docs describe Spawnite at launch, and some parts are still being built.

useAuthorityEffect

useAuthorityEffect(effect, dependencies): void

A useEffect that runs only where outcomes are decided, and receives the world’s authority: on the room and in a game played alone, never on a page in a room, whose room runs it. What a logic component writes as it mounts goes here, such as a scene placing its spawns: useAuthorityEffect((authority) => { const crate = spawn(authority, crate); return () => destroy(authority, crate); }, []).

Its cleanup undoes what it did, since StrictMode, a hot reload, a change of dependencies and a scene’s start again each run the cleanup and then the effect again. Inside a view, or outside a scene, such as a menu beside the canvas, it throws in development, naming the component, and in a built game logs once and runs nothing. Most setup belongs in a plugin’s setup or a system; a view sends a command instead. A logic component that hands the authority to a view’s callback lets the view write: keep it inside the effect. As Unity’s Start on a server world.

Parameter Type
effect (authority) => void | (() => void)
dependencies DependencyList

void