@weavix/sdk-react
v0.0.27
Published
Generic plugin SDK React package — framework-agnostic `PluginProvider` and hooks, no Tracker-specific types.
Readme
@weavix/sdk-react
Generic plugin SDK React package — framework-agnostic PluginProvider and hooks, no Tracker-specific types.
Automatically includes @weavix/sdk-core as a dependency.
Installation
npm install @weavix/sdk-react
# @weavix/sdk-core is installed automaticallyUsage
import { PluginProvider, usePluginContext } from '@weavix/sdk-react';
// Wrap your app
root.render(
<PluginProvider>
<App />
</PluginProvider>
);
// Use in components
function App() {
const { slot, slotContext, theme, language, registerHandler } = usePluginContext();
return <div>Slot: {slot}</div>;
}
// Full context (requires contextLevel: "full" in manifest)
function AppFull() {
const { slotContext } = usePluginContext('full');
// slotContext: unknown — cast to your type
const ctx = slotContext as { entityId: string };
return <div>Entity: {ctx.entityId}</div>;
}What's included
PluginProvider— initializes the plugin, manages lifecycle, provides contextusePluginContext()— hook for accessing theme, language, slot, slotContext, registerHandlerisInternalUrl()— utility for checking if a URL is internal- Hooks:
useTheme,useLanguage,useIsYateam,useUserId,useConfirm,useToaster,useLocalizedString - Components:
PluginError,PluginLoader,ErrorBoundary - Re-exports from
@weavix/sdk-core:hostApi,uiApi,on,dispatchHostEvent, error codes, types (notrackerApi— use tracker-react packages for Tracker HTTP)
For Tracker plugins
Use @yandex-data-ui/tracker-plugin-sdk-react (internal) or @weavix/tracker-plugin-sdk-react (external) for fully typed Tracker-specific wrappers.
