Skip to content

API reference > @kontsedal/olas-react > SuspendOnUnmount

SuspendOnUnmount() function ​

Wrap a sub-tree so unmount calls controller.suspend() and re-mount calls controller.resume() instead of disposing. The React tree is still unmounted (this is NOT Vue-style <KeepAlive> DOM preservation — DOM, scroll, focus, input state are NOT retained); only the *controller* stays alive and its effects pause. Use it for routed sub-trees whose computed state is expensive to rebuild but whose DOM you're happy to re-render. See spec §20.10.

**Cross-fade safe.** Multiple wrappers around the same controller are refcounted: resume() fires only when the FIRST mounts and suspend() only when the LAST unmounts. So during a cross-fade — the entering screen mounts while the exiting one is still mounted — the controller stays resumed regardless of the order React runs the effects, and the exiting screen's unmount can't suspend a controller the entering screen still uses (T4.6). suspend() should still be idempotent for safety.

**Shares its bookkeeping with useSuspendOnHidden.** A first mount while a hidden tab holds the controller suspended leaves it suspended until the tab shows. Once the last wrapper unmounts, the tab showing again does not resume it.

Signature:

typescript
export declare function SuspendOnUnmount(props: SuspendOnUnmountProps): ReactElement;

Parameters ​

Parameter

Type

Description

props

SuspendOnUnmountProps

Returns:

ReactElement

Released under the MIT License.