Official JavaScript/TypeScript SDKs for Togglely -- a self-hosted, multi-tenant feature toggle management platform.
| Package | npm | Use Case | Framework |
|---|---|---|---|
@togglely/sdk-core |
npm i @togglely/sdk-core |
Shared engine, server-side, custom integrations | Framework-agnostic |
@togglely/sdk-react |
npm i @togglely/sdk-react |
React apps, Next.js (SSR/SSG) | React 18+ |
@togglely/sdk-vue |
npm i @togglely/sdk-vue |
Vue apps, Nuxt (SSR) | Vue 3 |
@togglely/sdk-svelte |
npm i @togglely/sdk-svelte |
Svelte apps, SvelteKit (SSR) | Svelte 4/5 |
@togglely/sdk |
npm i @togglely/sdk |
Vanilla JS, CDN script tag, Node.js scripts | Browser / Node.js |
@togglely/sdk-react (includes hooks, components, SSR helper)@togglely/sdk-vue (includes composables, directives, plugin)@togglely/sdk-svelte (includes stores, actions, runes support)@togglely/sdk (global helpers, DOM helpers, CDN)@togglely/sdk-core (direct client API)All framework SDKs depend on @togglely/sdk-core internally; you never need to install it separately.
npm install @togglely/sdk-react
import { TogglelyProvider, useToggle } from '@togglely/sdk-react';
function App() {
return (
<TogglelyProvider
apiKey="your-api-key"
project="my-project"
environment="production"
baseUrl="https://togglely.io"
>
<MyComponent />
</TogglelyProvider>
);
}
function MyComponent() {
const isEnabled = useToggle('new-feature', false);
return isEnabled ? <NewFeature /> : <OldFeature />;
}
npm install @togglely/sdk-vue
import { createApp } from 'vue';
import { createTogglely } from '@togglely/sdk-vue';
const app = createApp(App);
app.use(createTogglely({
apiKey: 'your-api-key',
project: 'my-project',
environment: 'production',
baseUrl: 'https://togglely.io',
}));
<script setup>
import { useToggle } from '@togglely/sdk-vue';
const isEnabled = useToggle('new-feature', false);
</script>
<template>
<NewFeature v-if="isEnabled" />
<OldFeature v-else />
</template>
npm install @togglely/sdk-svelte
<script>
import { initTogglely, toggle } from '@togglely/sdk-svelte';
initTogglely({
apiKey: 'your-api-key',
project: 'my-project',
environment: 'production',
baseUrl: 'https://togglely.io',
});
const isEnabled = toggle('new-feature', false);
</script>
{#if $isEnabled}
<NewFeature />
{:else}
<OldFeature />
{/if}
npm install @togglely/sdk
import { initTogglely, isEnabled } from '@togglely/sdk';
initTogglely({
apiKey: 'your-api-key',
project: 'my-project',
environment: 'production',
baseUrl: 'https://togglely.io',
});
const enabled = await isEnabled('new-feature', false);
Or via CDN:
<script src="https://unpkg.com/@togglely/sdk/dist/index.umd.min.js"></script>
<script>
Togglely.initTogglely({ apiKey: 'your-api-key', project: 'my-project', environment: 'production', baseUrl: 'https://togglely.io' });
Togglely.isEnabled('new-feature').then(function(enabled) { /* ... */ });
</script>
All SDKs support tenantId (or brandKey) for multi-tenant projects:
// React
<TogglelyProvider tenantId="brand-a" ... />
// Vue
app.use(createTogglely({ tenantId: 'brand-a', ... }));
// Svelte
initTogglely({ tenantId: 'brand-a', ... });
// Core
const client = new TogglelyClient({ tenantId: 'brand-a', ... });
All SDKs support four offline fallback methods (in priority order):
TOGGLELY_* prefix)window.__TOGGLELY_TOGGLES)See Core SDK: Offline Fallback for details.
Pull toggles at build time for offline/static deployments:
npx @togglely/sdk-core togglely-pull \
--apiKey=your-api-key \
--project=my-project \
--environment=production \
--output=./toggles.json
Set user attributes for server-side targeting rules:
// React
const client = useTogglelyClient();
client.setContext({ userId: '123', country: 'DE' });
// Vue
const { setContext } = useTogglelyContext();
setContext({ userId: '123', country: 'DE' });
// Core
client.setContext({ userId: '123', country: 'DE' });
Three built-in strategies control how toggles stay up to date:
| Strategy | Description | Best for |
|---|---|---|
manual (default) |
Cached reads are side-effect free; call refresh() explicitly |
Frontend apps |
interval |
Background refresh on a fixed interval | Dashboards, internal tools |
stale-while-revalidate |
Cached reads may trigger a throttled background refresh | Interactive apps |
MIT