Devtools manual React setup
Prerequisites
- Node.js
- A React project created with Create React App or another React framework
- A Builder account with an API key
Set up
1. Install the required packages
Run the following command to install the necessary packages for Builder and React:
2. Add a dev task to npm scripts
Update the scripts section in your package.json file to include a development task. This task runs both the React development server and Builder Dev Tools concurrently:
Make sure you have concurrently installed. If not, install it using:
3. Create a .env file with your Builder API key
Add your Builder API key to a .env file in the root of your project:
Press Cmd/Ctrl + k and filter for api to get your Public API Key. For details see Using Builder API Keys.
4. Create a builder-registry.ts file
Create a new file at src/builder-registry.ts to register your custom components with Builder.
This file defines the components that will be available in the Visual Editor.
In src/builder-registry.ts, define and register any custom components you want to use within Builder.
Starter template:
For more details on registering components, see Register custom components.
5. Create a Figma imports component
Create a new component at src/components/figma-imports.tsx to preview Figma imports within Builder.
You can do the following with the Figma imports component:
- Preview designs imported from Figma within your React application
- See how your custom components render with Builder.io content
- Test the integration between Builder.io and your React app
6. Add the Figma imports component to your router
Add the figma-imports component as a route in your React router only in development mode.
For example, you can conditionally render the route based on the environment:
Test your set up
After completing the setup, follow these steps to verify that everything is working correctly:
- Start your developement server using
npm run dev. - Navigate to
http://localhost:3000/figma-importsin your browser. - If everything is set up correctly, you should see either a blank page or existing content from Builder for the figma-imports model.
- You can configure your components in Visual Editor and they will appear in your React application.
Troubleshoot your app
- Blank page: verify that the API key is correct and that content exists for the figma-imports model in Builder.
- 404 error: check if the route is correctly configured in the router.
- Component not rendering: verify that components are registered in
builder-registry.ts. - Build errors: confirm that all dependencies are installed and that the React version is compatible with Builder.
What's next
Now that you have set up Devtools for React, you can do the following with Builder:
- Register custom components in the
builder-registry.tsfile. - Create content in Builder using the Visual Editor.
- Import designs from Figma and map them to your components.
- Configure content models in Builder.
- Integrate Builder content into your main app.
For more details, see the Builder React documentation.