@savvagent/solid
v1.0.1
Published
SolidJS SDK for Savvagent feature flags with reactive primitives
Maintainers
Readme
@savvagent/solid
SolidJS SDK for Savvagent with reactive primitives (signals and resources).
Installation
npm install @savvagent/solidQuick Start
import { SavvagentProvider, createFlag } from '@savvagent/solid';
import { Show } from 'solid-js';
function App() {
return (
<SavvagentProvider config={{ apiKey: 'sdk_...' }}>
<MyFeature />
</SavvagentProvider>
);
}
function MyFeature() {
const flag = createFlag('new-feature');
return (
<Show when={!flag.loading()} fallback={<div>Loading...</div>}>
<Show when={flag.value()} fallback={<OldFeature />}>
<NewFeature />
</Show>
</Show>
);
}API Reference
createFlag(flagKey, options)
Create a reactive flag with full state.
const flag = createFlag('new-feature', {
context: { user_id: userId() },
defaultValue: false,
realtime: true,
});
// Access values
flag.value(); // boolean
flag.loading(); // boolean
flag.error(); // Error | null
flag.refetch(); // force re-evaluationcreateFlagValue(flagKey, options)
Simple accessor for flag value only.
const isEnabled = createFlagValue('new-feature');
return <Show when={isEnabled()}><NewFeature /></Show>;createUserSignals()
Manage user identification.
const [userId, setUserId] = createUserSignals();
createEffect(() => {
setUserId(currentUser()?.id || null);
});License
MIT
