Skip to main content

Overview

Registers a cleanup callback that runs before the app’s iframe is destroyed. Use this to save state, close connections, or perform other cleanup.

Import

import { useTeardown } from 'sunpeak';

Signature

function useTeardown(
  callback: () => Promise<void> | void
): void

Parameters

callback
() => Promise<void> | void
required
Cleanup function to run before app destruction.

Returns

return
void
This hook does not return a value.

Usage

import { useTeardown } from 'sunpeak';
import { useCallback } from 'react';

function MyResource() {
  const cleanup = useCallback(async () => {
    console.log('App is being torn down');
    // Save state, close connections, etc.
  }, []);

  useTeardown(cleanup);

  return <div>My Resource</div>;
}