JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 40
  • Score
    100M100P100Q71550F
  • License Apache-2.0

A simplified layer on top of @matrix-widget-toolkit/api to use it in a React based widget.

Package Exports

  • @matrix-widget-toolkit/react
  • @matrix-widget-toolkit/react/build/cjs/index.js
  • @matrix-widget-toolkit/react/build/esm/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@matrix-widget-toolkit/react) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@matrix-widget-toolkit/react

@matrix-widget-toolkit/react

This is package that provides a Widget API intergration for React apps.

Usage

Install it with:

yarn add @matrix-widget-toolkit/react

Providing the Widget API to React components

While this package contains a <WidgetApiProvider> you probably don't want to use this package most of the time. Prefer using @matrix-widget-toolkit/mui or @matrix-widget-toolkit/semantic-ui which internally use this package to share functionality.

Acessing the Widget API

Once the Widget API is provided to React components, use the useWidgetApi hook to access it:

import { useWidgetApi } from '@matrix-widget-toolkit/react';

const widgetApi = useWidgetApi();

Mocking the Widget API

Most of the time you will use <MuiWidgetApiProvider> to initialize and provide the WidgetApi to your react components. However, if you want to mock it in tests, you can use <WidgetApiMockProvider> to provide a mocked version:

import { WidgetApiMockProvider } from '@matrix-widget-toolkit/react';

<WidgetApiMockProvider value={widgetApi}>
  /* Your child components */
</WidgetApiMockProvider>;