Lifecycle
MAESTROSDK.beforeRefresh(handler)
Registers a function that runs before Cowork refreshes this Mini App's tab, for example when the person presses the refresh button. Use it to keep unsaved work: ask, save, or cancel the refresh.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
handler | () => boolean | void | Promise<boolean | void> | Yes | Runs once per refresh. Return false (or a promise that resolves to false) to cancel the refresh. Anything else lets it go ahead |
Returns
() => void: call it to remove this handler.
Behaviour
- Handlers run one after another, in the order they were added, and each is awaited.
- The first handler that returns
falsecancels the refresh. A handler that throws or rejects also cancels it. - With no handler, the tab refreshes at once.
- Only one refresh is handled at a time; a second request while one is running is ignored.
- A
handlerthat is not a function is ignored, and the returned function does nothing.
Example
js
const off = MAESTROSDK.beforeRefresh(async () => {
if (!form.dirty) return;
return await MAESTROSDK.confirm({ title: 'Refresh?', message: 'Unsaved changes will be lost.' });
});
// later
off();Related
- Interaction
confirm, often used insidebeforeRefresh - Overview All modules of the Mini App SDK