Skip to main content
Hooks and the app’s own components, so your pages look like the rest of the app. React’s own hooks (useState, useEffect, …) come from react.
Hooks and components marked 2.1 were added in SDK 2.1.0. Using them requires "sdkVersion": "^2.1.0".

Hooks

useProjectState

State that survives restarts, stored separately per project. Keyed by your expansion id, so two expansions can both keep a count.

useGlobalState

The same, but shared across every project, for a preference that belongs to the expansion.
Both are for small, JSON-serialisable values. They share their store with sdk.storage: useGlobalState reads storage.*, and useProjectState reads storage.project(id).*, on mount. For project data, write to the project with sdk.project.

useProject

The open project’s id, or null. Follows navigation.

useNavigate

route opens a page registered with sdk.routes.register.

useWindowTitle

Sets the window title while the component is mounted.

useSetting

2.1
One of your expansion’s app settings, by the element’s local id. Live: it updates when the value changes on the Settings page or through sdk.settings.set.

useItem

2.1
Inside the item editor (an injection or a module component), the item being edited and a setter. Null elsewhere. setField goes through the editor’s history, presence and autosave, exactly like a built-in edit.

useT

2.1
Your expansion’s strings from sdk.i18n.strings. Re-renders when the user changes language.

useTheme

2.1
theme is the selected theme id, mode is 'dark' or 'light', and cssVar(name) reads a CSS variable’s current value. Live.

More hooks

2.1

Components

Components take the props the app uses for them; onChange on inputs receives the value, not the event. Buttons and inputs Layout and containers Feedback and display ContextMenu items are { key, label, icon, shortcut, danger, disabled, hidden, onClick }, or { type: 'separator' }. Items, textures and models Icons CodeEditor, VanillaItemPicker, ItemPreview, ItemPicker, DataTable, TexturePreview, PixelEditor and RichTextInput load on first render, so they may take a moment the first time. The kit has no sound or effect picker. Build one with Select and sdk.minecraft.sounds() or effects():

Styling

Import a CSS file and it is scoped to your expansion, so plain element selectors are safe:
See Modules and imports. To restyle the app itself, use sdk.theme.

Errors

If one of your components throws while rendering, only that spot is replaced, by a card naming the file and line, with a Retry button. The rest of the app carries on. See Lifecycle.