Skip to Content
Grist Widgets

SDK

Add grist-widget-sdk to an existing Vite or Next.js project, then the core hooks every widget uses.

grist-widget-sdk wraps the Grist plugin API — the JavaScript bridge between a custom widget iframe and a Grist document — into one hook, a provider, and a boundary. New here? The Overview says what it does and when to use the plugin API on its own.

Already have a scaffolded project (Your first widget)? Its dependencies and plugin-api script tag are pre-wired — skip ahead to Hello world. This page is for adding the SDK to a project you already have.

Install

pnpm add grist-widget-sdk
# or
npm install grist-widget-sdk
# or
yarn add grist-widget-sdk

Peer dependencies:

react       >=18
react-dom   >=18

Load the Grist plugin API

The SDK expects the global grist object at runtime. Add the script in your app shell:

<script src="https://docs.getgrist.com/grist-plugin-api.js"></script>

Hello world

A widget is a declaration and a component, in src/app/App.tsx:

import { defineGristWidget } from "grist-widget-sdk"

export const widget = defineGristWidget({
  title: "Hello",
  requiredAccess: "read table",
})

export default function App() {
  const w = widget.useGrist()
  if (w.mode === "empty") return <p>Select a row.</p>
  if (w.mode === "new-row") return <p>Add the row in Grist.</p>
  return <p>Selected row #{w.record?.id}</p>
}

and one call mounts it, in src/main.tsx:

import { mountGristWidget } from "grist-widget-sdk/app"
import * as entry from "./app/App"

mountGristWidget(entry, { dev: import.meta.env.DEV })

That is everything you need to:

  • wait for Grist to answer, and show a page when it is opened outside Grist;
  • show a screen while access or columns are missing, with a retry;
  • re-render on the selected row, in empty, row or new-row mode.

See Mounting a widget for what mountGristWidget() renders, and the Overview for why use this package instead of calling grist directly.

What useGrist() returns

GroupProperties
Connectionstatus, error, reload(), theme
Selection and mappingrecord, records, mode, currentTableId, mappings, columnMappingStatus, mappedRecord, resolveMappedColumnId, mapBack
Writes (records)table, getTable(id), actionStatus, actionError
Writes (schema)applyActions(actions)
ReadsfetchRows, listTables, listColumns
Widget optionswidgetOptions, setWidgetOptions, patchWidgetOptions
LinkingsetCursorPosition, setLinkedRowSelection
Attachments / RESTgetAttachmentUrl, fetchAttachmentBlob, uploadAttachment, fetchWithAuth

See the API reference for every field.

Asking for write access and declared columns

In the widget configuration panel, the user maps these logical names to real columns. You consume them via w.mappedRecord and w.updateRecord(...) on writes — see Declare and map columns.

Run a write

w.updateRecord(...) writes the selected row, w.table.update([...]) many rows as one action, and w.applyActions([...]) changes the schema. Write data explains each.

Explore the rest of the SDK

Guide contents

TopicWhat it covers
OverviewWhy use this package instead of calling grist directly
Declare and map columnsNaming the columns a widget needs, and reading and writing under those names
Read dataThe section kept up to date, and other tables on demand
Write dataUnder your names, any table, the schema
Widget optionsPersisting per-section settings in Grist's own store
Attachments & RESTAttachment bytes, SQL, and the REST API via pre-authenticated fetch
Widget linking & themeDriving another widget's cursor; adopting the document theme
Typed readsRecords typed from the declaration, checked cell by cell
Errors and alertsWhere a widget's problems show
PerformanceHow useGrist() re-renders, and keeping large widgets fast
TroubleshootingSymptom-first fixes

See the API reference for every exported symbol, and the Replica document for the shape a document is reduced to for tests and tooling.

Where to go next

  • Overview — why it exists, and when to reach for the raw plugin API instead.
  • Core concepts — the mental model behind selection modes, mappings, and the ready handshake.
  • CLI reference — scaffold a new project instead of adding the SDK to an existing one.
  • Emulator — test widgets without a live Grist document.

On this page