React Quickstart
Add a co-pilot panel to your React app in under 5 minutes.
What you'll build:
- A slide-out assistant panel with co-pilot chat
- A sidebar trigger (or custom button) that opens the panel
- Your first action the AI can suggest
Build with AI
Option 1: Install the Pillar skill (recommended for ongoing development)
If you're using Claude Code, Cursor, or Windsurf, install the Pillar skill for best practices guidance:
npx skills add pillarhq/pillar-skills --skill pillar-best-practices
Then just ask your coding assistant to "Add Pillar to my app" and it will follow our recommended patterns.
Option 2: Use this prompt (one-time setup)
Use this prompt to have an AI coding assistant set up Pillar SDK in your project:
# Set Up Pillar SDK for My App
Analyze my codebase and create a complete Pillar SDK integration with actions, context sync, and handlers.
## What Pillar Does
Pillar provides:
- A co-pilot chat panel that answers user questions using your knowledge base
- Suggested actions that users can execute directly in your app
- Plans that guide users through multi-step workflows
## Your Task
### 1. Analyze My Project
- Identify my framework (Next.js App Router, Next.js Pages, Vite, CRA, etc.)
- Find the right place to add PillarProvider (layout.tsx, App.tsx, _app.tsx, etc.)
- If using Next.js App Router, create a client wrapper component in providers/
### 2. Install and Configure
- Install packages: `npm install @pillar-ai/sdk @pillar-ai/react`
- Add PillarProvider to the app root
- Create .env.local with NEXT_PUBLIC_PILLAR_PRODUCT_KEY set to your product key
### 3. Generate Actions (10-15 based on my app)
Look at my routes, features, and modals to generate actions:
```tsx
// lib/pillar/actions.ts
import { defineActions } from '@pillar-ai/sdk';
export const actions = defineActions({
// Navigation actions based on my routes
// Trigger actions for modals/wizards I have
// Admin-only actions with requiredContext
});
```
### 4. Create RouteContextSync Component
Sync the current route to Pillar so the AI knows where the user is:
```tsx
// components/RouteContextSync.tsx
'use client';
import { usePillar } from '@pillar-ai/react';
import { usePathname } from 'next/navigation';
export function RouteContextSync() {
const { pillar } = usePillar();
const pathname = usePathname();
useEffect(() => {
pillar?.setContext({ currentPage: pathname });
}, [pillar, pathname]);
return null;
}
```
### 5. Create PillarActionHandlers Component
Handle action execution with proper routing:
```tsx
// components/PillarActionHandlers.tsx
'use client';
import { usePillar } from '@pillar-ai/react';
import { useRouter } from 'next/navigation';
export function PillarActionHandlers() {
const { pillar } = usePillar();
const router = useRouter();
useEffect(() => {
if (!pillar) return;
const handlers = [
pillar.onTask('navigate', ({ path }) => {
router.push(path);
return { success: true };
}),
// Add handlers for trigger_action types
];
return () => handlers.forEach(unsub => unsub?.());
}, [pillar, router]);
return null;
}
```
### 6. Add Assistant Button (if sidebar is disabled)
If the edge trigger sidebar is disabled, create a custom button to open the panel.
## Start Here
First, explore my codebase structure:
1. Look at the routing structure (pages/, app/, or routes/)
2. Find existing providers/layout patterns
3. Identify modals, settings pages, and key features
4. Look for auth patterns to understand user roles
Then implement all the above components.
Prerequisites
- React 18+ (this guide uses Next.js examples, but works with Vite, CRA, etc.)
- A Pillar account (sign up at trypillar.com)
- Your help center slug (found in Settings → General)
Step 1: Install the SDK
npm install @pillar-ai/sdk @pillar-ai/react
Or with other package managers:
# yarnyarn add @pillar-ai/sdk @pillar-ai/react# pnpmpnpm add @pillar-ai/sdk @pillar-ai/react
Step 2: Create the Provider
Since PillarProvider uses React context, create a client component wrapper:
import { PillarProvider } from '@pillar-ai/react';export function App() {return (<PillarProvider productKey="your-product-key" publicKey="pk_...">{/* Your app */}</PillarProvider>);}
Configuration Options
All configuration is optional. Pass options via the config prop.
enabledShow the sidebar tab on the screen edge. When enabled, users can click it to open the assistant panel. Set to false if you want to use your own trigger button instead.
true.enabledShow a floating action button on mobile devices.
Defaults totrue.breakpointViewport width in pixels below which the mobile trigger appears (and edge trigger hides).
Defaults to700.positionCorner position of the floating button.
Defaults to'bottom-right'.iconPreset icon to display in the button.
Defaults to'sparkle'.customIconCustom SVG string. Overrides the preset icon if provided.
backgroundColorCSS color for the button background. Defaults to the theme's primary color.
iconColorCSS color for the icon.
Defaults to'white'.sizeButton size. Presets: 'small' (44px), 'medium' (56px), 'large' (68px). Or pass a pixel value.
'medium'.labelTooltip text and aria-label for accessibility.
Defaults to'Get help'.offsetDistance from screen edges in pixels.
Defaults to24.enabledEnable the assistant panel.
Defaults totrue.positionWhich side of the screen the panel appears on.
Defaults to'right'.modeHow the panel interacts with your content. 'push' shifts content aside; 'overlay' slides over content.
'push'.widthPanel width in pixels.
Defaults to380.useShadowDOMStyle isolation. Set to false to let custom cards use your app's CSS (Tailwind, etc.). Set to true for full isolation on third-party sites.
false.hoverBreakpointBelow this viewport width, the panel hovers over content instead of pushing it. Set to false to always push.
1200.hoverBackdropShow a backdrop overlay when the panel is in hover mode.
Defaults totrue.fullWidthBreakpointBelow this viewport width, the panel takes full screen width.
Defaults to500.modeColor mode. 'auto' follows the user's system preference.
'auto'.colorsCustom colors for light mode. Available keys: primary, primaryHover, background, backgroundSecondary, text, textMuted, border, borderLight.
darkColorsCustom colors for dark mode (same keys as colors). Used when mode is 'auto' or 'dark'.
enabledShow a help button when users select text on the page.
Defaults totrue.labelButton label text.
Defaults to'Ask co-pilot'.enabledCheck URL parameters for auto-opening the panel (e.g., ?pillar-open=true).
true.prefixPrefix for URL parameters.
Defaults to'pillar-'.clearAfterOpenRemove URL parameters from the address bar after opening.
Defaults totrue.customCSSCustom CSS to inject into the panel. Use public class names (e.g., .pillar-header, .pillar-message-user) to override default styles.
onReadyCallback fired when the SDK is fully initialized.
onErrorCallback fired when an error occurs during initialization.
<PillarProviderproductKey="your-product-key"config={{edgeTrigger: {enabled: true,},mobileTrigger: {enabled: true,position: 'bottom-right',icon: 'sparkle',size: 'medium',},panel: {position: 'right',mode: 'push',width: 380,},theme: {mode: 'auto',colors: {primary: '#2563eb',},},textSelection: {enabled: true,label: 'Ask co-pilot',},urlParams: {enabled: true,prefix: 'pillar-',},}}onReady={() => console.log('Ready')}onError={(err) => console.error(err)}/>
<PillarProviderproductKey="your-product-key"config={{edgeTrigger: {enabled: true,},mobileTrigger: {enabled: true,position: 'bottom-right',icon: 'sparkle',size: 'medium',},panel: {position: 'right',mode: 'push',width: 380,},theme: {mode: 'auto',colors: {primary: '#2563eb',},},textSelection: {enabled: true,label: 'Ask co-pilot',},urlParams: {enabled: true,prefix: 'pillar-',},}}onReady={() => console.log('Ready')}onError={(err) => console.error(err)}/>
Minimal Setup (with sidebar)
If you want the default sidebar tab to appear on the screen edge:
<PillarProvider helpCenter={process.env.NEXT_PUBLIC_PILLAR_PRODUCT_KEY!}>{children} {/* Your app content renders here */}</PillarProvider>
No additional button is needed — the edge trigger provides the entry point.
Without Sidebar (custom button only)
If you prefer a custom button instead of the sidebar:
<PillarProviderhelpCenter={process.env.NEXT_PUBLIC_PILLAR_PRODUCT_KEY!}config={{edgeTrigger: { enabled: false },mobileTrigger: { enabled: false },}}>{children} {/* Your app content renders here */}</PillarProvider>
When disabling the sidebar, you'll need to add your own trigger button — see Step 5.
Step 3: Add to Layout
Wrap your app with the provider in your root layout:
// app/layout.tsximport { PillarSDKProvider } from '@/providers/PillarSDKProvider';export default function RootLayout({ children }: { children: React.ReactNode }) {return (<html lang="en"><body><PillarSDKProvider>{children} {/* Your page content renders here */}</PillarSDKProvider></body></html>);}
Step 4: Add Environment Variables
Create or update your .env.local file:
# .env.localNEXT_PUBLIC_PILLAR_PRODUCT_KEY=your-help-center-slug
Where to find your help center slug: In the Pillar dashboard, go to Settings → General. Your help center slug is displayed under "Help Center URL".
Step 5: Create an Assistant Button (Optional)
Note: This step is only required if you disabled the edge trigger sidebar in Step 2. By default, Pillar shows a sidebar tab on the screen edge that opens the panel — no custom button needed.
If you disabled the sidebar and want a custom button to open the assistant panel:
// components/AssistantButton.tsx'use client';import { usePillar } from '@pillar-ai/react';export function AssistantButton() {const { open, isPanelOpen } = usePillar();return (<buttononClick={() => open()}className="fixed bottom-4 right-4 bg-primary text-white px-4 py-2 rounded-full shadow-lg">{isPanelOpen ? 'Close' : 'Ask Assistant'}</button>);}
Add it to your layout or a page:
// app/layout.tsximport { AssistantButton } from '@/components/AssistantButton';// Inside PillarSDKProvider:<PillarSDKProvider>{children} {/* Your page content */}<AssistantButton /></PillarSDKProvider>
Step 6: Test It
- Start your development server:
npm run dev - Click the sidebar tab on the screen edge (or your custom assistant button)
- Ask a question in the co-pilot chat
The panel will open and you can interact with your co-pilot.
Next Steps
- Add actions that the AI can suggest to users
- Customize the theme to match your brand
- Add user context for personalized help
- Configure the panel position and behavior