Builder is a new headless CMS with full visual drag-and-drop page-building abilities. It’s easy to integrate into any site and you can even use your custom code components in the visual editor! Using any tech stack we can work with Builder.io.
There are two ways to create a new react project to integrate Builder.
npm init builder.io
2. Pick a starter and select the language you want to use in your project. Here I am selecting React.
3. Enter the project name and confirm by entering the “Y”.
After confirming the project name creating a project and adding dependencies will be started. This will take some time.
For this example, the name of the project is “my-builder-app”
npx create-react-app my-builder-app
cd my-app
npm install @builder.io/react
npm run build
npm run dev
import { BuilderComponent, builder } from '@builder.io/react'
builder.init("YOUR_BUILDER_API_KEY")
export const MyComponent = () => {
const [builderContentJson, setBuilderContentJson] = useState(null)
useEffect(() => {
builder.get('page', { url: location.pathname })
.promise().then(setBuilderContentJson)
}, [])
return
}
In the case of the existing react app, you can skip steps 1 & 2. Directly you can start with adding the builder dependency. Follow steps 3 to step 6 from above.
Now use the builder with the app follow the below steps
2. After login into the builder get the API key.
3. Add the API key into your codebase.
For building the UI you can use three types of models
Let’s start with the page model. For creating the UI with a page model open the https://builder.io/content
Create a new page
For creating a page click on the “Create Page” CTA. After clicking it will ask to choose a template. You can select an inbuilt template. If you want to create UI from scratch choose “Blank”.
Let’s try with a blank template to create the home page.
Below are the built-in components in builder.io
In the above section, you have seen the built-in components but now you can also create your own custom component and use, them as built-in components, are used.
Create a components folder in your project. Create the TSX or JSX component. Below is an example of creating the custom component. Let’s create a Heading component.
In the above code snippet, there are 2 steps to do
Import builder and BuilderComponent.
Register your component as in the following example. Here, register component() registers a Heading component with one text input: title and color
The registerComponent(component, options) method takes two arguments:
You can find your component under “Custom Component”. Below is an example of using the custom component.
After completion of UI publish your page by clicking the “Publish” button. By publishing the page, it going to be live. You can see the output by running your site.
Now you can check the published page by running your site. Here I am testing with localhost.