A React Hook that runs a function only once when the component mounts in an Activity component.
Unlike useMount, this hook ensures the callback is executed only once strictly, even when the Activity is hidden and shown again. This is particularly useful for initialization logic that should only run once in Activity contexts, not every time the component becomes visible.
Toggle the Activity to see the difference:
useActivityMount only executes once (initial mount)useMount executes every time Activity becomes visibleSee API for more details.
Click links below to view source on GitHub.
A function that will be called when the component mounts, can be async.
The callback will only execute once when the component first mounts, and will NOT re-execute when the Activity is shown again after being hidden.
| Hook | Behavior in Activity | Use Case |
|---|---|---|
useMount | Runs when Activity becomes visible | Use for side effects that should happen every time content is shown |
useActivityMount | Runs only once on first mount | Use for initialization logic that should only run once (e.g., data fetching, subscriptions) |
This hook internally uses useMount with strictOnce=true, which ensures the callback only runs once by using a ref to track execution status.
The Activity API is a React feature that allows components to be hidden (using display: none) while preserving their state. This is different from unmounting, where the component is completely removed from the DOM.