Search documentation

Search for docs or ask AI

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:

bash
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:

Tip: Use.to enable Plan mode in Cursor for best results
# 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

bash
npm install @pillar-ai/sdk @pillar-ai/react

Or with other package managers:

bash
# yarn
yarn add @pillar-ai/sdk @pillar-ai/react
# pnpm
pnpm add @pillar-ai/sdk @pillar-ai/react

Step 2: Create the Provider

Since PillarProvider uses React context, create a client component wrapper:

providers/PillarSDKProvider.tsx
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.

Properties
enabled
boolean

Show 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.

Defaults to true.
enabled
boolean

Show a floating action button on mobile devices.

Defaults to true.
breakpoint
number

Viewport width in pixels below which the mobile trigger appears (and edge trigger hides).

Defaults to 700.
position
'bottom-right' | 'bottom-left'

Corner position of the floating button.

Defaults to 'bottom-right'.
icon
'sparkle' | 'question' | 'help' | 'chat' | 'support'

Preset icon to display in the button.

Defaults to 'sparkle'.
customIcon
string

Custom SVG string. Overrides the preset icon if provided.

backgroundColor
string

CSS color for the button background. Defaults to the theme's primary color.

iconColor
string

CSS color for the icon.

Defaults to 'white'.
size
'small' | 'medium' | 'large' | number

Button size. Presets: 'small' (44px), 'medium' (56px), 'large' (68px). Or pass a pixel value.

Defaults to 'medium'.
label
string

Tooltip text and aria-label for accessibility.

Defaults to 'Get help'.
offset
number

Distance from screen edges in pixels.

Defaults to 24.
enabled
boolean

Enable the assistant panel.

Defaults to true.
position
'left' | 'right'

Which side of the screen the panel appears on.

Defaults to 'right'.
mode
'push' | 'overlay'

How the panel interacts with your content. 'push' shifts content aside; 'overlay' slides over content.

Defaults to 'push'.
width
number

Panel width in pixels.

Defaults to 380.
useShadowDOM
boolean

Style 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.

Defaults to false.
hoverBreakpoint
number | false

Below this viewport width, the panel hovers over content instead of pushing it. Set to false to always push.

Defaults to 1200.
hoverBackdrop
boolean

Show a backdrop overlay when the panel is in hover mode.

Defaults to true.
fullWidthBreakpoint
number

Below this viewport width, the panel takes full screen width.

Defaults to 500.
mode
'light' | 'dark' | 'auto'

Color mode. 'auto' follows the user's system preference.

Defaults to 'auto'.
colors
object

Custom colors for light mode. Available keys: primary, primaryHover, background, backgroundSecondary, text, textMuted, border, borderLight.

darkColors
object

Custom colors for dark mode (same keys as colors). Used when mode is 'auto' or 'dark'.

enabled
boolean

Show a help button when users select text on the page.

Defaults to true.
label
string

Button label text.

Defaults to 'Ask co-pilot'.
enabled
boolean

Check URL parameters for auto-opening the panel (e.g., ?pillar-open=true).

Defaults to true.
prefix
string

Prefix for URL parameters.

Defaults to 'pillar-'.
clearAfterOpen
boolean

Remove URL parameters from the address bar after opening.

Defaults to true.
customCSS
string

Custom CSS to inject into the panel. Use public class names (e.g., .pillar-header, .pillar-message-user) to override default styles.

onReady
() => void

Callback fired when the SDK is fully initialized.

onError
(error: Error) => void

Callback fired when an error occurs during initialization.

Full Example
<PillarProvider
productKey="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:

examples/quickstarts/react/minimal-setup-provider.tsx
<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:

examples/quickstarts/react/provider-without-sidebar.tsx
<PillarProvider
helpCenter={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:

examples/quickstarts/react/layout-provider.tsx
// app/layout.tsx
import { 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:

examples/quickstarts/react/env-local.bash
# .env.local
NEXT_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:

examples/quickstarts/react/assistant-button.tsx
// components/AssistantButton.tsx
'use client';
import { usePillar } from '@pillar-ai/react';
export function AssistantButton() {
const { open, isPanelOpen } = usePillar();
return (
<button
onClick={() => 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:

examples/quickstarts/react/layout-with-assistant-button.tsx
// app/layout.tsx
import { AssistantButton } from '@/components/AssistantButton';
// Inside PillarSDKProvider:
<PillarSDKProvider>
{children} {/* Your page content */}
<AssistantButton />
</PillarSDKProvider>

Step 6: Test It

  1. Start your development server: npm run dev
  2. Click the sidebar tab on the screen edge (or your custom assistant button)
  3. Ask a question in the co-pilot chat

The panel will open and you can interact with your co-pilot.

Next Steps