Skip to content

About

Utilities for building XBlock frontend code with React

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

@opencraft/xblock-react-utils

React utilities, hooks, and context for building Open edX XBlocks.

Installation

pnpm add @opencraft/xblock-react-utils

What's included

Main package

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.

Testing utilities

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.

About

Utilities for building XBlock frontend code with React

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages