Skip to main content

Page Action | Update

Easily create reactive apps by updating the UI with page.update(). Compose will diff the previous UI against the new one and intelligently update any components that have changed.

import { Compose, Page, UI } from "@composehq/sdk"

function handler({ page, ui }: { page: Page, ui: UI }) {
let count = 0;

page.add(() => ui.stack([
ui.header(`Count: ${count}`),
ui.button("increment-btn", {
label: "Increment",
onClick: () => {
count += 1
page.update()
}
}),
]))
}

const app = new Compose.App({ name: "Counter", handler })

Note: page.update() was introduced in version 0.21.0 of the SDK.

Common pitfalls

When working with objects, you need to reassign the variable itself rather than just modifying a nested property for page.update() to detect the change.

import { Compose, Page, UI } from "@composehq/sdk"

function handler({ page, ui }: { page: Page, ui: UI }) {
let data = { count: 0 };

function onClick() {
// This won't work
data.count += 1
// Do this instead
data = { ...data, count: data.count + 1 }

page.update()
}

page.add(() => ui.stack([
ui.json(data),
ui.button("increment-btn", {
label: "Increment",
onClick
}),
]))
}

const app = new Compose.App({ name: "Counter", handler })

API reference

Function signature

page.update(): void

Parameters

None.

Returns

void