Portal Community

Automatic Cleanup Summary

Hook / ComponentWhat Gets Cleaned UpWhen
InteractionProviderinteractions.{userId} subscription, dismiss subscriptionOn unmount or user ID change
useInteractionReceiver()Reads from shared context — no subscription leak possible
useInteractionCallback(id)interactions.ack.{id} subscriptionOn response received, unmount, or id change
useInteraction()If the component unmounts while awaiting, the Promise is cancelledOn unmount

Unmount Safety

If a component that called useInteraction() unmounts before the response arrives (e.g., the user navigates away), the hook automatically cancels the pending interaction. The promise rejection is swallowed internally — React's "Can't perform a state update on an unmounted component" warning will not appear.

// This is safe — even if the user navigates away before the manager responds
function ApprovalButton() {
  const { sendInteraction } = useInteraction();
  const [status, setStatus] = useState('idle');

  const handleSend = async () => {
    setStatus('pending');
    try {
      const response = await sendInteraction({ ... });
      setStatus('complete'); // Only runs if still mounted
      showToast(response.outcome);
    } catch (err) {
      if (!isUnmountError(err)) {
        setStatus('error'); // Only runs if still mounted
      }
    }
  };
  // ...
}

User ID Change

If the user logs out and a new user logs in within the same app session, InteractionProvider detects the user ID change (from EdgeStreamProvider) and:

  1. Unsubscribes from the previous user's interaction topics
  2. Clears the interaction queue
  3. Subscribes to the new user's interaction topics

No manual cleanup is required on your end.

React Strict Mode

EdgeInteract hooks are compatible with React Strict Mode. In Strict Mode, effects run twice in development. The subscription setup/teardown cycle handles this correctly — double subscriptions are deduplicated by the EdgeStream client.

No Cleanup Required If you use only InteractionProvider, InteractionContainer, and the provided hooks, you will never need to write manual cleanup code. The library handles everything.