Reblock is a library for building interactive Slack surfaces with React and Slack Bolt. You can use all of the familiar features of React, like hooks and context, to build Slack modals, messages, and home tabs, without dealing with the complicated, cumbersome JSON or implementing your own interactivity and state management.
import Reblock from 'reblock-js'
import { useState } from 'react'
function Increment() {
const [count, setCount] = useState(0)
return (
<>
<rich>
Count: <code>{count}</code>
</rich>
<button onEvent={() => setCount(count + 1)}>Increment</button>
</>
)
}
Reblock.appHome(app, (userID) => (
<>
<rich>
Hello <user>{userID}</user>!
</rich>
<Increment />
</>
))
First, install Reblock from NPM.
$ bun i reblock-js
$ npm i reblock-js
$ yarn add reblock-js
Then, import the library. You can use the default export or import individual functions and types.
/** @jsxImportSource reblock-js */
import Reblock from 'reblock-js'
import { appHome } from 'reblock-js'
The comment is needed for the correct JSX types to load, but it isn't needed for the code to run. You can also add jsxImportSource to your tsconfig.json.
{
"compilerOptions": {
// other options...
// if using bun, see https://bun.sh/docs/typescript#suggested-compileroptions
"jsx": "react-jsx",
"jsxImportSource": "reblock-js"
}
}
Coming soon, hopefully! The functions are typed, and all the elements are typed, but TypeScript doesn't allow you to restrict what elements can go in what other elements. For now, message me for help!
Contributions and bug reports are welcome! If you are in the Hack Club Slack, you can also DM me (@Jeremy) with any feedback or questions. If you make something cool with Reblock, please let me know!
main.ts
: Main library code, exports all functionshelpers.ts
: Helper functions used across the libraryevents.ts
: Sets up event listeners for Slack eventsrenderer.ts
: Takes React components and, withreact-reconciler
, converts it to a JSX object treejsx/
: Contains all the functions for converting the JSX object tree to Slack Block Kit JSONblocks.ts
: Converts JSX objects to blocksrichText.ts
: Converts JSX objects to rich textelements.ts
: Converts JSX objects to elements
surfaces/
: Contains the Root classes which connect React to different Slack surfaceshome.ts
: Renders to the App Homemessage.ts
: Renders to a messagemodal.ts
: Renders to a modalblocks.ts
: Renders to Block Kit JSON (non-interactive)
jsx-runtime/
: Re-exports React's JSX runtime with Reblock typesjsx-types.ts
: Types for the JSX namespacejsx-runtime.ts
: Re-exportsreact/jsx-runtime
with Reblock typesjsx-dev-runtime.ts
: Re-exportsreact/jsx-dev-runtime
with Reblock types