React utilities, hooks, and context for building Open edX XBlocks.
pnpm add @opencraft/xblock-react-utils| Export | Description |
|---|---|
createXBlockRoot |
Entry point for mounting a React XBlock. Handles Paragon themes, Shadow DOM, and providers. |
useHandlerUrl(name) |
Hook that returns the URL for an XBlock handler. |
RuntimeContext |
React context exposing runtime and element from the edX platform. |
callServer(JQueryAjaxSettings) |
Wrapper for jQuery AJAX calls to XBlock handlers so you can use them with async/await. |
saveStudioBlock(params) |
Convenience wrapper for saving XBlock Studio configuration which notifies the runtime on start, end, and error. Uses callStudio under the hood. |
XBlockRuntime, XBlockConfig |
TypeScript types for the XBlock runtime and config. |
Import from @opencraft/xblock-react-utils/testing. Requires vitest and @testing-library/react.
| Export | Description |
|---|---|
render |
Wraps @testing-library/react's render with StrictMode and IntlProvider. Also re-exports everything from @testing-library/react. |
mockRuntime() |
Returns a mock XBlockRuntime with vitest spies. |