Create the MEDKit Control Object¶
Create one MEDKit SDK instance after configuring your Twitch Extension Client ID. Reuse that instance for state, configuration, PubSub, and signed REST requests.
Load MEDKit¶
Install the supported package in your extension project:
npm install @muxy/extensions-js@2.4.18
Import the browser bundle through your build system:
import Muxy from "@muxy/extensions-js";
Initialize the SDK¶
muxy.js
import Muxy from "@muxy/extensions-js";
Muxy.setup({
clientID: import.meta.env.VITE_MUXY_CLIENT_ID,
});
export const medkit = new Muxy.SDK();
export async function initializeMuxy() {
await medkit.loaded();
return medkit;
}
Call initializeMuxy() once during application startup. loaded() resolves after Twitch authorization and the initial Muxy state/configuration payload are available.
Read initial data¶
const sdk = await initializeMuxy();
const config = sdk.getConfig();
const state = sdk.getState();
console.log({ config, state });
Do not create a new SDK object for every component or request. Pass the shared instance through your application state or dependency-injection layer.