This is package that provides a Widget API intergration for React apps.
Install it with:
yarn add @mgcm/react
While this package contains a <WidgetApiProvider>
you probably don't want to use this package most of the time.
Prefer using @mgcm/mui
which internally use this package to share functionality.
Once the Widget API is provided to React components, use the useWidgetApi
hook to access it:
import { useWidgetApi } from '@mgcm/react';
const widgetApi = useWidgetApi();
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 '@mgcm/react';
<WidgetApiMockProvider value={widgetApi}>
/* Your child components */
</WidgetApiMockProvider>;