Skip to main content

state

const

Declare a piece of state your mod owns and persists. The value type is read off `TValue` by the authoring compiler, so the host can validate every write. `initial` is checked the same way at declaration time. What you get back is a declaration, not a value you can read. Pass it to `ctx.state(declaration)` inside a handler to get the handle with `.value` and `.set()`.

const state: StateFactory

Import

import { state } from '@modular/sdk/state';

Notes

example
```ts const runCount = state<number>({ id: 'my-mod.runCount', scope: 'workspace', initial: 0, }); command({ id: 'my-mod.run', title: 'Run', run: async ctx => { const count = ctx.state(runCount); await count.set(count.value + 1); }, }); ```
category
State