How to import code components into Webflow
In this quickstart guide, we’ll discuss how to import React components from an external codebase into Webflow using DevLink.
What you’ll accomplish:
- Set up your development environment
- Declare a Webflow code component with props
- Import your component library to Webflow
- Use your component in a Webflow project
Before you start
Before running this quickstart, make sure you have:
- A Webflow account with either:
- a Workspace on a Freelancer, Core, Growth, Agency, or Enterprise plan
- a Webflow site with a CMS, Business, or Enterprise plan
- A Webflow site where you can test components
- Node.js 20+ and npm 10+ installed
- Basic familiarity with React components and TypeScript
1. Setup your development environment
Set up your local development environment to create and share React components.
Setup your React project
DevLink is compatible with a wide variety of local setups. To get started, create a new React project.
If you’re working with an existing repository, you can skip this step.
Install the Webflow CLI
Install the Webflow CLI and the necessary dependencies to create a code component library.
2. Define a Webflow code component
Create a code component definition file to map a React component to a Webflow component. In this step, you’ll create a Badge component with two props mapping to an example Badge.tsx component.
Create a code component file
In your editor, navigate to the your src or components directory where you added your Badge component. Create a new file called Badge.webflow.tsx. This file will define how your Badge component appears in Webflow.
Import the React component and Webflow functions
Import the necessary dependencies to create your code component: the React component, prop types and the declareComponent function.
Declare the component
Declare the code component using the declareComponent function.
The declareComponent function takes two parameters:
- Your React component (
Badge) - Configuration options:
name: The name of the componentdescription?: A description of the component (optional)group?: The group the component belongs to (optional)props?: The props of the component, which we’ll define in the next step. (optional)options?: The options of the component, (optional)
For more information and detailed configuration options for code component imports, see the component definition reference.
Define the component props
Add configurable properties that users can edit in the Webflow designer.
Add a props object to the declareComponent function. This object defines which properties designers can configure in the Webflow editor, and maps them to appropriate Webflow prop types using the props constructor.
This code component defines two props:
text: A text field for the Badge contentvariant: A dropdown with predefined style options
3. Share your library to Webflow
In your terminal, run the following command to upload your library:
The Webflow CLI will:
- Authorize your workspace: The CLI will check for a Workspace authentication token in your
.envfile. If one is not found, the CLI will prompt you to authenticate by opening a browser window to the Workspace authorization page. Authorize a workspace to continue. - Bundle your library: The CLI will bundle your library, and ask you to confirm the components you want to share.
- Upload your library to your Workspace
For more information and detailed configuration options for bundling and importing React components, see the bundling and import reference. →
4. Use the component on your Webflow site
Add your component to the canvas and update the props to customize the component.