@builder.io/react

中文文档
9.4.11发布于 2026/11/05MITTypeScriptESM + CJS构建来源已验证近 30 天下载 29.4万

NOTE: If you want to register your React Server Components as custom components in Builder, you will need to use our experimental NextJS SDK here.

原始使用文档
文档目录11 节
  1. Minimum supported version
  2. Integration
  3. React API
  4. Simple example
  5. Registering Components
  6. BuilderComponent
  7. Builder
  8. BuilderContent
  9. builder
  10. Guide to use API Version v3 to query for content
  11. Node v20 + M1 Macs (Apple Silicon) Support

Builder.io React SDK

NOTE: If you want to register your React Server Components as custom components in Builder, you will need to use our experimental NextJS SDK here.

Minimum supported version

The peerDependencies permit React and React DOM >=16.8.0 (and React 19 release candidates). This is an installation range, not a guarantee of active support for React 16. The E2E-tested minimum is React and React DOM 18.2.0; see the framework version matrix.

Integration

See our full getting started docs, or jump right into integration. We generally recommend to start with page building as your initial integration:

Integrate Page Building Integrate Section Building Integrate CMS Data
CTA to integrate page building CTA to integrate section building CTA to integrate CMS data

React API

Simple example

The gist of using Builder, is fetching content (using queries on custom fields and targeting. Builder is structured like a traditional headless CMS where you can have different content types, called models. By default, every Builder space has a "page" model.

import { builder } from '@builder.io/react'

const API_KEY = '...' // Your Builder public API key
const MODEL_NAME = 'page';

const content = await builder
  .get(MODEL_NAME, {
    // Optional custom query
    query: {
      'data.customField.$gt': 100,
    },
    // Optional custom targeting
    userAttributes: {
      urlPath: '/' // Most Builder content is targeted at least by the URL path
    }
  })
  .promise()

// Later, pass the fetched content to the BuilderComponent
<BuilderComponent model={MODEL_NAME} content={content} />

The builder content is simply json that you pass to a <BuilderComponent /> to render. Learn more about it here

You can view all of the options for builder.get for fetching content in our full reference here

For example, with Next.js, to render Builder as your homepage:

export const getStaticProps = async () => {
  return {
    props: {
      builderContent: await builder
        .get('page', {
          userAttributes: {
            urlPath: '/', // Fetch content targeted to the homepage ("/" url)
          },
        })
        .promise(),
    },
  };
};

export default function MyHomePage({ builderContent }) {
  return (
    <>
      <YourHeader />
      <BuilderComponent model="page" content={builderContent} />
      <YourFooter />
    </>
  );
}

You can also allow dynamic page building (the ability to create new pages on new URLs dynamically). E.g. see this guide on how to do that

Registering Components

One of Builder's most powerful features is registering your own components for use in the drag and drop editor. You can choose to have these compliment the built-in components, or to be the only components allowed to be used (e.g. via components-only mode)

import { Builder } from '@builder.io/sdk-react';

function MyHero(props) {
  /* Your own hero component in your codebase */
}

Builder.registerComponent(MyHero, {
  name: 'Hero',
  inputs: [
    { name: 'title', type: 'string' }, // Gets passed as the `title` prop to the Hero
  ],
});

Learn more about registering components in Builder

BuilderComponent

You can find the full reference docs for the BuilderComponent props here

const MODEL_NAME = 'page';

// Render
<BuilderComponent model={MODEL_NAME} content={builderJson} />;

See our guides for Gatsby and Next.js for guides on using with those frameworks

Passing data and functions down

You can also pass data and functions down to the Builder component to use in the UIs (e.g. bind data values to UIs e.g. for text values or iterating over lists, and actions to trigger for instance on click of a button)

All data passed down is available in Builder actions and bindings as state.*, for instance in the below example state.products, etc will be available

<BuilderComponent
  model="page"
  data={{
    products: productsList,
    foo: 'bar',
  }}
  content={builderJson}
/>

You can also pass down functions, complex data like custom objects and libraries you can use context. Similar to React context, context passes all the way down (e.g. through symbols, etc). This data is not observed for changes and mutations

<BuilderComponent
  model="page"
  context={{
    addToCart: () => myService.addToCart(currentProduct),
    lodash: lodash,
  }}
  content={builderJson}
/>

Context is available in actions and bindings as context.*, such as context.lodash or context.myFunction() in the example above

Passing complex data

Everything passed down is available on the state object in data and actions - e.g. state.products[0].name

See more about using data passed down here

Builder

The global Builder singleton has a number of uses. Most important is registering custom components.

import * as React from 'react';
import SyntaxHighlighter from 'react-syntax-highlighter';
import { Builder } from '@builder.io/react';

class CodeBlockComponent extends React.Component {
  render() {
    return <SyntaxHighlighter language={this.props.language}>{this.props.code}</SyntaxHighlighter>;
  }
}

Builder.registerComponent(CodeBlockComponent, {
  name: 'Code Block',
  inputs: [
    {
      name: 'code',
      type: 'string',
      defaultValue: 'const incr = num => num + 1',
    },
    {
      name: 'language',
      type: 'string',
      defaultValue: 'javascript',
    },
  ],
});

See our full guide on registering custom components here.

See the full reference docs for registerComponent options here.

BuilderContent

Usage with Data Models

Although you can already fetch data models from our Content API directly and use it as you would any other API resource, with a BuilderContent component you are able to use live Editing / Previewing / A/B testing of your Data Models within the Builder Visual Editor.

Example, setting up an editable theme:
 <BuilderContent model="site-settings"> { (data, loading) => {
   If (loading) {
     return <Spinner />
   }
   return <>
      /*pass values down to an example ThemeProvider, used as a wrapper in your application*/
       <ThemeProvider theme={data.theme} >
           {props.children}
       </ThemeProvider>
   </>
   }}
</BuilderContent>

Or an example fetching server side and passing the content using the content prop, e.g. in Next.js

export const getStaticProps = async () => {
  return {
    props: {
      builderDataContent: await builder.get('site-settings', /* other options like queries and targeting */).promise()
    }
  }
}

export default function MyPage({ builderDataContent }) {
  return <BuilderContent content={builderDataContent}>{data =>
    <ThemeProvider theme={data.theme}>
      {/* ... more content ... */}
    </ThemeProvider>
  </BuilderContent>
}

Usage with Page/Section Custom Fields

Page and section models in builder can be extended with custom fields. To enable live editing / previewing on components that uses those custom fields, you can use BuilderContent to pass input data from the model to your components that are outside the rendered content

Example, passing Custom Field input:
<BuilderContent model="landing-page">
  {data => {
    /*use your data here within your custom component*/
    return (
      <>
        <FeaturedImage image={data.featuredImage} />
        <BuilderComponent content={content} model="landing-page" />
      </>
    );
  }}
</BuilderContent>

Passing content manually

This is useful for doing server side rendering, e.g. with Gatsby and Next.js or via loading data from other sources than our default APIs, such as data in your own database saved via webhooks

const content = await builder.get(‘your-data-model’, { ...options });
if (content) {
  /*use your data here*/
  return <BuilderContent model="your-data-model" content={content} >
}

Advanced querying

When using custom models and fields you can do more advanced filtering of your content with queries and targeting

import { BuilderContent, builder } from '@builder.io/react';

builder.setUserAttributes({ isLoggedIn: false })

export default () => <div>
  <BuilderContent
     model="your-data-model"
     options={{ query: { 'data.something.$in': ['value a', 'value b'] } }} />
  <!-- some other content -->
</div>

builder

The React SDK exports the core SDK's builder object, which can be used for setting things like your API key and user attributes

import { builder } from '@builder.io/react';

builder.init(YOUR_KEY);

// Optional custom targeting
builder.setUserAttributes({
  userIsLoggedIn: true,
  whateverKey: 'whatever value',
});

Lite version

NOTE: If you want a zero-dependencies, fast and small Builder SDK for React, we strongly encourage you to try out our Gen 2 React SDK. You can find it here.

This SDK has a lite version where it provides only the bare minimum of components needed to render your Builder content, it won't have any built-in components registered by default, this option should work with custom components. The main difference is that you need to specifically add any built-in components you want to use or they won’t show up. To use the lite package, you change all your imports from @builder/react to @builder/react/lite and then import only the built-in components that you want to use:

// Change all imports from '@builder.io/react' to '@builder.io/react/lite'
import { BuilderComponent } from '@builder.io/react/lite';

// Import only what built-in components you like to use
import '@builder.io/react/dist/lib/src/blocks/Button';
import '@builder.io/react/dist/lib/src/blocks/Columns';

Guide to use API Version v3 to query for content

For using API Version v3, you need to pass apiVersion as "v3" in the init function. For example:

import { builder } from '@builder.io/react';

// First, initialize the SDK with your API key
builder.init('YOUR_API_KEY_GOES_HERE');
// Then, set the API version to v3
builder.apiVersion = 'v3';

Reasons to switch to API Version v3

  • Better, more scalable infra: Query v3 is built on global scale infrastructure to ensure fast response times and high availability
  • Ability to ship more features, faster: Query V3 will allow us to keep shipping the latest features to our customers without breaking fundamental flows. These will be shipped only to Query V3 and not to the older versions of the query API

Coming soon...

  • Better support for localization: Some of the newer features of localization and querying based on it will be better supported in Query V3
  • Support multi-level nested references: Query V3 will allow you to query, resolve, and return content that has nested references of other contents and symbols.

Node v20 + M1 Macs (Apple Silicon) Support

The SDKs rely on isolated-vm, a library to securely execute code on a Node server. There is a compatibility issue for that library when running on Node v20 and M1 Macs. To workaround this issue, you must provide NODE_OPTIONS=--no-node-snapshot to the command that runs your server.

If you do not provide this flag, the SDK will skip using isolated-vm. This will only occur on Apple Silicon machines that are running Node v20.

For more information, see this issue.

版本与发布记录

@builder.io/react 共发布 1,305 个版本,首次发布于 2018/08/30;过去 12 个月发布了 23 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
9.4.11latest2026/11/053 天前
9.4.102026/10/2019 天前
9.4.10-02026/10/1524 天前
9.4.92026/10/1524 天前
9.4.82026/09/281 个月前
9.4.72026/09/181 个月前

其他发布通道:nightly → 0.1.118-0,react-15-nightly → 0.1.121-0,react-15-beta → 0.1.121-3,react-15 → 0.1.122,backport-v1.x → 1.1.54,react-5.x-lts → 5.0.12。

关于 @builder.io/react 的常见问题

@builder.io/react 是什么?

NOTE: If you want to register your React Server Components as custom components in Builder, you will need to use our experimental NextJS SDK here.

如何安装 @builder.io/react?

在项目目录运行 npm install @builder.io/react,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(>=16.8.0 || ^19.0.0-rc)、react-dom(>=16.8.0 || ^19.0.0-rc)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@builder.io/react 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@builder.io/react 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@builder.io/react 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=6.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@builder.io/react 可以商用吗?

@builder.io/react 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@builder.io/react 的下载量有多少?

根据 npm 官方下载统计,@builder.io/react 在 2026/10/09 – 2026/11/07 这 30 天内被下载 294,446 次,日均约 9,815 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@builder.io/react 还在维护吗?

最新版本 9.4.11 发布于 2026/11/05(3 天前);至今共发布 1305 个版本,其中过去 12 个月发布了 23 个;首次发布于 2018/08/30。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。