// Expert guidance for developing React code components for Webflow. This skill should be used when users are building, troubleshooting, or optimizing React components for import into Webflow Designer, working with Shadow DOM styling, managing component communication, or configuring the Webflow CLI.
| name | webflow-code-components |
| description | Expert guidance for developing React code components for Webflow. This skill should be used when users are building, troubleshooting, or optimizing React components for import into Webflow Designer, working with Shadow DOM styling, managing component communication, or configuring the Webflow CLI. |
This skill provides expert guidance for building React code components that integrate with Webflow Designer. It covers component architecture, prop configuration, styling within Shadow DOM, state management across isolated components, and CLI workflows.
Trigger this skill when users are:
useWebflowContextCode components run as isolated React applications in Shadow DOM:
Key constraint: React Context, Redux, Zustand, and similar state management libraries do NOT work across separate component instances. Use alternative communication patterns instead.
project/
├── .env # Workspace API token (gitignored)
├── webflow.json # CLI configuration
├── webpack.webflow.js # Optional webpack overrides
└── src/
└── components/
└── ComponentName/
├── ComponentName.tsx # React component
├── ComponentName.module.css # Styles
└── ComponentName.webflow.tsx # Webflow declaration
Install dependencies:
npm i --save-dev @webflow/webflow-cli @webflow/react @webflow/data-types
Create webflow.json:
{
"library": {
"name": "Component Library Name",
"components": ["./src/**/*.webflow.@(js|jsx|mjs|ts|tsx)"]
}
}
Authenticate:
npx webflow library share for interactive auth, OR.env: WEBFLOW_WORKSPACE_API_TOKEN=your_tokenComponentName.tsx)ComponentName.module.css)ComponentName.webflow.tsx)npx webflow library shareAlways use declareComponent in .webflow.tsx files:
import { declareComponent } from '@webflow/react';
import { props } from '@webflow/data-types';
import { Component } from './Component';
import './Component.module.css'; // ← Import styles HERE
export default declareComponent(Component, {
name: 'Component Name',
description: 'Brief description',
group: 'Category', // Optional: 'Interactive', 'Content', 'Layout', etc.
props: {
propName: props.Text({
name: 'Display Name',
defaultValue: 'default value',
group: 'Prop Group', // Optional
tooltip: 'Help text' // Optional
}),
},
options: {
applyTagSelectors: false, // Default: false
ssr: true, // Default: true
},
});
Critical: Always import styles in .webflow.tsx, not just in .tsx.
Quick reference for available prop types:
| Type | Returns | Use For |
|---|---|---|
props.Text() | string | Single-line text |
props.RichText() | string | Multi-line text |
props.TextNode() | string | Canvas-editable text |
props.Link() | { href, target, preload } | URLs (requires wrapper) |
props.Image() | string | Image URLs |
props.Number() | number | Numeric values |
props.Boolean() | boolean | Toggles |
props.Variant() | string | Dropdown options |
props.Visibility() | boolean | Show/hide controls |
props.Slot() | ReactNode | Flexible content areas |
props.Color() | string | Color picker ⚠️ NOT YET AVAILABLE |
props.ID() | string | HTML element IDs ⚠️ NOT YET AVAILABLE |
For detailed configuration options for each prop type, refer to references/prop-types.md.
Note: Some prop types are documented but not yet available in the current Webflow release. Do not use prop types marked as "NOT YET AVAILABLE".
props.Link() returns an object, but React components often expect separate props. Use wrapper components:
// Component.webflow.tsx
import { props, PropType, PropValues } from "@webflow/data-types";
import { Component, ComponentProps } from "./Component";
type WebflowProps = {
link: PropValues[PropType.Link];
} & Omit<ComponentProps, "href" | "target">;
const WebflowComponent = ({ link: { href, target }, ...rest }: WebflowProps) => {
return <Component href={href} target={target} {...rest} />;
};
export default declareComponent(WebflowComponent, {
// ... configuration
});
For complete wrapper patterns and other complex transformations, refer to references/wrapper-components.md.
.webflow.tsx - Styles must be imported in declaration filevar(--variable-name, fallback)var(--colors-primary, #007bff)font-family: inherit works across Shadow boundaryGet variable names from Webflow Designer:
background-color: var(--colors-primary, #007bff);Enable site-wide tag styles (h1, p, etc.) with:
declareComponent(Article, {
options: {
applyTagSelectors: true,
},
});
For comprehensive styling strategies, Shadow DOM workarounds, and CSS-in-JS configuration, refer to references/styling.md.
Since React Context doesn't work across component instances, use these patterns:
| Method | Best For | Persistence |
|---|---|---|
| URL Parameters | Filters, search state, navigation | Browser history |
| localStorage | User preferences, settings | Across sessions |
| sessionStorage | Temporary session data | Until tab closes |
| Nano Stores | Complex shared state, reactive updates | In-memory only |
| Custom Events | One-way notifications, broadcasts | Event-based |
URL Parameters:
const url = new URL(window.location.href);
url.searchParams.set('filter', 'active');
window.history.pushState({}, '', url);
window.dispatchEvent(new Event('urlchange'));
localStorage + Events:
localStorage.setItem('theme', 'dark');
window.dispatchEvent(new CustomEvent('theme-changed', { detail: { theme: 'dark' } }));
Nano Stores:
npm install nanostores @nanostores/react
import { atom } from 'nanostores';
export const $cart = atom<CartItem[]>([]);
For complete communication patterns, type-safe implementations, and complex state sharing examples, refer to references/component-communication.md.
.env files not supportedconst [data, setData] = useState(null);
const [loading, setLoading] = useState(true);
const [error, setError] = useState(null);
useEffect(() => {
const controller = new AbortController();
fetch(apiUrl, { signal: controller.signal })
.then(res => res.json())
.then(setData)
.catch(err => {
if (err.name !== 'AbortError') setError(err.message);
})
.finally(() => setLoading(false));
return () => controller.abort();
}, [apiUrl]);
For complete data fetching patterns, caching strategies, POST requests, and error handling, refer to references/data-fetching.md.
Access current Webflow environment information:
import { useWebflowContext } from '@webflow/react';
const { mode, interactive, locale } = useWebflowContext();
Returns:
mode - Current Webflow mode (design, publish, etc.)interactive - Whether component should be interactivelocale - User's locale string or nullCommon use cases:
defaultExpanded={!interactive}draggable={interactive}translations[locale] || translations.enif (mode === 'design') { /* show helpful message */ }For detailed hook usage, mode types, and advanced patterns, refer to references/hooks.md.
Disable SSR (ssr: false) when component uses:
window, document, localStorage)Keep SSR enabled (default) for:
If SSR is needed but some browser APIs are used:
useEffect(() => {
if (typeof window !== 'undefined') {
// Browser-only code
setWidth(window.innerWidth);
}
}, []);
For SSR architecture details, hydration, and React Server Components limitations, refer to references/architecture.md.
Import components:
npx webflow library share
Bundle locally:
npx webflow library bundle --public-path http://localhost:4000/
View import logs:
npx webflow library log
--verbose - Detailed output for debugging--dev - Development mode (no minification)--no-input - Skip prompts (for CI/CD)--api-token <token> - Pass token directlyFor complete CLI reference, webpack configuration, CSS Modules setup, and CI/CD integration, refer to references/cli-reference.md.
Note: Webflow Designer MCP tools may not be available in all environments. Always check for tool availability before attempting to use them.
// Check if Webflow MCP tools are available
const hasWebflowMCP = typeof mcp__webflow__sites_list === 'function';
if (!hasWebflowMCP) {
// MCP tools not available - use alternative approach
console.log('Webflow Designer MCP not available');
}
Model Context Protocol (MCP) tools for Webflow Designer allow you to programmatically:
Use cases:
Check tool availability (see above)
Get site information:
const { sites } = await mcp__webflow__sites_list();
const site = sites.find(s => s.displayName === 'My Site');
Provide connection link to user:
Click this link to connect:
[Launch Webflow Designer](https://{shortName}.design.webflow.com?app={appId})
Wait for user confirmation that Designer is connected
Navigate and make changes:
// Switch to page
await mcp__webflow__de_page_tool({
siteId: site.id,
actions: [{ switch_page: { page_id: pageId } }]
});
// Ask user to select target element
// User MUST manually select in Designer
// Create content
await mcp__webflow__element_builder({
siteId: site.id,
actions: [{
parent_element_id: selectedElementId,
creation_position: "append",
element_schema: {
type: "Paragraph",
set_text: { text: "Content here" }
}
}]
});
User must manually select elements:
section-inner--about section, then let me know when ready"Connection can drop:
Element creation is sequential:
Common tasks:
mcp__webflow__sites_list()mcp__webflow__pages_list({ site_id })mcp__webflow__de_page_tool({ siteId, actions: [{ switch_page }] })mcp__webflow__element_tool({ siteId, actions: [{ get_selected_element }] })mcp__webflow__element_builder({ siteId, actions: [...] })mcp__webflow__sites_publish({ site_id })For complete Designer MCP documentation, patterns, troubleshooting, and API reference, refer to references/webflow-designer-mcp.md.
webflow.json matches files.webflow.tsx extension.webflow.tsx (not just .tsx)import styles from './Component.module.css'.env--api-token flagFor comprehensive troubleshooting, error messages, and solutions, refer to references/troubleshooting.md.
prefers-reduced-motionReact.memo for expensive componentsuseEffectFor complete best practices, code examples, and detailed patterns, refer to references/best-practices.md.
Use these references for detailed information:
references/getting-started.md - Setup, installation, first componentreferences/component-declaration.md - Complete declareComponent APIreferences/prop-types.md - All prop types with full configurationreferences/wrapper-components.md - Transform complex prop typesreferences/hooks.md - useWebflowContext patterns and examplesreferences/architecture.md - Shadow DOM, React roots, SSR detailsreferences/styling.md - CSS strategies, Shadow DOM, site variablesreferences/component-communication.md - State sharing patternsreferences/data-fetching.md - API integration, caching, requestsreferences/cli-reference.md - All CLI commands and optionsreferences/webflow-designer-mcp.md - Webflow Designer MCP tools (if available)references/best-practices.md - Comprehensive recommendationsreferences/troubleshooting.md - Common issues and solutionsWhen helping users develop components:
Progressive disclosure: Load reference files only when needed for specific questions:
references/getting-started.mdreferences/prop-types.mdreferences/styling.mdreferences/component-communication.mdreferences/troubleshooting.mdThis keeps context efficient while providing comprehensive guidance when required.