Skip to content

toolmark-monorepo / @toolmark/react / ToolScope

Function: ToolScope() ​

ToolScope(props): Element

Defined in: packages/react/src/scope.tsx:37

Groups tools registered by its subtree under one named scope (spec §5).

The scope is created lazily, during render, into a ref: children mount (and register their tools) before ToolScope's own effect runs, so the scope must already exist by then. The mount effect disposes the scope on cleanup and clears the ref; if a later mount effect finds the ref empty (a React StrictMode remount, whose cleanup already ran) it re-creates the scope and forces one more render so the subtree re-registers into the live scope.

Under SSR (renderToString/renderToStaticMarkup, no document) effects never run, so nothing would ever dispose a scope created during render, so this skips creating one server-side and provides undefined instead (core's server-side Scope.scope() also returns a detached node, so a repeated renderToString against one module-level registry never accumulates child scopes).

Known limit: a render React discards before commit (a suspended or interrupted concurrent render) may leave the scope it created behind. Such a node is empty — its children never mounted, so no tool is registered in it — and stays attached to its parent until the parent is disposed.

Parameters ​

props ​

ToolScopeProps

See ToolScopeProps.

Returns ​

Element