Define a code component

declareComponent(Component, data)

The declareComponent function is used to create a code component declaration. See the declare code component guide for more information.

Syntax

1declareComponent(Component, data): void;

Parameters

  • Component: The React component to declare
  • Data: An object with: Component metadata, prop definitions, and optional configurations

Data object

The data object is used to define the component’s metadata, prop definitions, and optional configurations. It takes the following properties:

PropertyTypeDescription
namestringThe name of the component
description?stringA description of the component (optional)
group?stringGroup of the component in the component panel (optional)
propsobjectProps for the user to edit in Webflow. See the prop types reference for more information.
options?objectOptional configurations including applying tag selectors, and managing SSR.

Example

Button.webflow.tsx
1import { declareComponent } from '@webflow/react';
2import { props } from '@webflow/data-types';
3import { Button } from './Button';
4// import '../styles/global.css'; // Import global styles
5
6// Declare the component
7export default declareComponent(Button, {
8
9 // Component metadata
10 name: "Button",
11 description: "A button component with a text and a style variant",
12 group: "Interactive",
13
14 // Prop definitions
15 props: {
16 text: props.Text({
17 name: "Button Text",
18 defaultValue: "Click me"
19 }),
20 variant: props.Variant({
21 name: "Style",
22 options: ["primary", "secondary"],
23 defaultValue: "primary"
24 }),
25 },
26 // Optional configuration
27 options: {
28 applyTagSelectors: true,
29 },
30});