0.1.13-alpha โข Published 5 months ago
@onboardjs/react v0.1.13-alpha
@onboardjs/react
Official React bindings for @onboardjs/core: Build fully custom, dynamic onboarding flows in React and Next.js with maximum flexibility.
โจ Features
- Headless-first: Bring your own UIโOnboardJS manages the logic.
- React Hooks API: Use
useOnboarding()to access state and actions. - Context-based:
OnboardingProvidermanages and distributes onboarding state. - Custom Step Components: Map any step to your own React component.
- Persistence: Built-in localStorage support, or plug in your own (e.g., Supabase).
- TypeScript-first: Full type safety and autocompletion.
- Next.js Ready: Works with App Router and Pages Router.
- Plugins: Extend functionality with custom plugins.
๐ Quickstart
1. Install
npm install @onboardjs/core @onboardjs/reactyarn add @onboardjs/core @onboardjs/react
# or
pnpm add @onboardjs/core @onboardjs/react
# or
bun add @onboardjs/core @onboardjs/react2. Define Your Steps and Components
// config/onboarding.ts
import { OnboardingStep } from '@onboardjs/core';
import { StepComponentProps } from '@onboardjs/react';
const WelcomeStep: React.FC<StepComponentProps<{ title: string }>> = ({ payload }) => (
<div>
<h1>{payload.title}</h1>
<p>Welcome to the app!</p>
</div>
);
const NameStep: React.FC<StepComponentProps<{ fieldKey: string }>> = ({ payload, onDataChange }) => (
<input
placeholder="Your name"
onChange={e => onDataChange({ [payload.fieldKey]: e.target.value }, e.target.value.length > 1)}
/>
);
export const steps: OnboardingStep[] = [
{
id: 'welcome',
type: 'CUSTOM_COMPONENT',
payload: { componentKey: 'welcome', title: 'Hello from OnboardJS!' },
nextStep: 'name',
},
{
id: 'name',
type: 'CUSTOM_COMPONENT',
payload: { componentKey: 'name', fieldKey: 'userName' },
nextStep: null,
},
];
export const stepRegistry = {
welcome: WelcomeStep,
name: NameStep,
};3. Wrap Your App with OnboardingProvider
// pages/onboarding.tsx or app/onboarding/page.tsx
'use client';
import { OnboardingProvider } from '@onboardjs/react';
import { steps, stepRegistry } from '@/config/onboarding';
import OnboardingUIManager from '@/components/OnboardingUIManager';
export default function OnboardingPage() {
return (
<OnboardingProvider
steps={steps}
localStoragePersistence={{
key: 'onboarding_v1',
// ttl: 1000 * 60 * 60 * 24, // 1 day (optional)
}}
>
<OnboardingUIManager stepsConfig={steps} stepComponentRegistry={stepRegistry} />
</OnboardingProvider>
);
}4. Build Your UI with useOnboarding
// components/OnboardingUIManager.tsx
'use client';
import { useOnboarding } from '@onboardjs/react';
export default function OnboardingUIManager({ stepsConfig, stepComponentRegistry }) {
const { state, next, isLoading } = useOnboarding();
if (!state || !state.currentStep) return <p>Loading...</p>;
if (state.isCompleted) return <p>Onboarding complete! ๐</p>;
const StepComponent =
state.currentStep.type === 'CUSTOM_COMPONENT'
? stepComponentRegistry[state.currentStep.payload.componentKey]
: null;
return (
<div>
<h2>{state.currentStep.title}</h2>
{StepComponent && (
<StepComponent
payload={state.currentStep.payload}
coreContext={state.context}
onDataChange={() => {}}
/>
)}
<button onClick={() => next()} disabled={isLoading}>Next</button>
</div>
);
}๐ Next.js Integration
- Client Components:
OnboardingProviderand any component usinguseOnboardingmust be a Client Component ('use client';). - Persistence: Use
localStoragePersistencefor out-of-the-box device bound progress saving, or provide your own handlers for Supabase, Neon, etc. - Examples: See onboardjs/apps/examples.
๐ Documentation & Community
- @onboardjs/core README
- Main Documentation Site@ onboardjs.com/docs
- Discord Discussions: Join the community
Build onboarding your way. Star the repo, join the community, and help us shape the future of onboarding for React and Next.js!
0.1.13-alpha
5 months ago
0.1.12-alpha
5 months ago
0.1.10-alpha
5 months ago
0.1.9-alpha
5 months ago
0.1.8-alpha
5 months ago
0.1.7-alpha
5 months ago
0.1.6-alpha
5 months ago
0.1.5-alpha
5 months ago
0.1.4-alpha
5 months ago
0.1.3-alpha
5 months ago
0.1.2-alpha
5 months ago
0.1.1-alpha
5 months ago