BlockKit component

The public API is exactly what the package entry exports. Deep imports are unsupported. This page covers the components; validation helpers are on the validation page and exported types on the types page.

<BlockKit />

Renders a full payload: parses string input, applies the theme, provides context, and dispatches every block.

import { BlockKit, type BlockKitAction, type BlockKitInput } from "react-blockkit";

export function handleAction(action: BlockKitAction) {
  console.log(action);
}

export function Preview({ payload }: { payload: BlockKitInput }) {
  return <BlockKit data={payload} theme="dark" onAction={handleAction} />;
}
PropTypeDefaultDescription
dataBlockKitInputrequiredPayload object, block array, or JSON string
theme"light" | "dark""light"Color theme; also sets color-scheme for native controls
surface"message" | "modal" | "home""message"Surface passed to context; never rejects a payload
onAction(action: BlockKitAction) => voidReceives local interactions from supported elements with an action_id; workflow_button renders but does not emit
resolversBlockKitResolversMaps user/channel/usergroup/team IDs, emoji, and dates to display values
classNamestringAppended to the root element's class list
aria-labelstring"Slack Block Kit preview"Accessible name for the root role="article" element

A string data that fails JSON.parse throws BlockKitInvariantError with code: "invalid_json". Everything block-shaped renders; see Unknown blocks and fallbacks.

<BlockKitProvider />

Supplies surface, resolvers, and the action handler to composed blocks. <BlockKit /> uses it internally; you only need it when rendering block or element components directly.

PropTypeDefault
childrenReactNoderequired
surfaceBlockKitSurface"message"
onAction(action: BlockKitAction) => void
resolversBlockKitResolvers

There is no theme prop here. Theming belongs to the <BlockKit /> root. The useBlockKitContext() hook exposes the current context value to custom components.

Block components

Every block type has a standalone component. All of them share one props shape:

import type { BlockComponentProps, SectionBlockData } from "react-blockkit";

// block, optional className, optional path (JSON path for fallback output)
export type SectionProps = BlockComponentProps<SectionBlockData>;
ComponentRenders
BlockAny RenderableBlock; dispatches on block.type, falls back on unknown types
ActionsBlockactions
AlertBlockalert
CardBlockcard
CarouselBlockcarousel
ContainerBlockcontainer (including collapsible state)
ContextBlockcontext
ContextActionsBlockcontext_actions
DataTableBlockdata_table
DataVisualizationBlockdata_visualization (pie, bar, line, area)
DividerBlockdivider
FileBlockfile
HeaderBlockheader (semantic h1h4 via level)
ImageBlockimage
InputBlockinput
MarkdownBlockmarkdown
PlanBlockplan
RichTextBlockrich_text
SectionBlocksection (text, fields, accessory)
TableBlocktable (plus TableCell for individual cells)
TaskCardBlocktask_card
VideoBlockvideo

Element components

Elements take the Slack object as element, plus optional className and the enclosing blockId (included in emitted actions):

ComponentRenders
InteractiveElementAny interactive element; dispatches on element.type
ButtonElementbutton
SelectElementAll static/external/users/channels/conversations selects and their multi_* variants
OverflowElementoverflow
ChoiceGroupcheckboxes and radio_buttons
InputElementText, email, URL, and number inputs; date/time/datetime pickers; file and rich-text inputs
ImageElementimage elements and accessories

Text primitives

ExportRole
TextRenders a TextObject, mrkdwn or plain text
MrkdwnRenders a mrkdwn string (formatting, links, mentions, emoji, dates)
RichTextRenders rich_text block elements
MarkdownRenders the markdown block's Markdown subset
tokenizeMrkdwn(text: string) => readonly MrkdwnToken[]; the mrkdwn tokenizer, usable without React
tokenizeMarkdownThe markdown-block tokenizer, usable without React

StyleX themes

tokens, lightTheme, and darkTheme export the renderer's StyleX variable group and themes for apps that also build with StyleX. CSS-only consumers never need them, because the precompiled react-blockkit/styles.css already contains both.