Components with state
Pass data from Builder or from your application directly to your custom component to customize styles or behaviors.
What to know
- Inputs to custom components in Builder are accessible to the component code through the component's props.
- Access dynamic values in Builder state within a custom component through the
builderStateproperty. - Pass data from your application directly into Builder state with the
dataattribute.
Access custom component options
When a custom component is provided an input option, that value can be accessed directly within the component through props. This value is defined in code, but can be manipulated in Builder's Visual Editor.
For example, the custom component below, CustomTip, accepts a single input called text.
Access the value within the custom component by referencing the value directly within props.
In the code snippet below, a CustomTip component is imported. That component is then passed to an object where custom components and their associated options are defined.
When using custom components, you must pass an array of components, which is demonstrated by the customComponents variable.
Within your content entry, pass in the custom components with the customComponents prop.
Access the value within the custom component by referencing the value directly within props.
For example, the custom component below, CustomTip, accepts a single input called text.
Access the value within the custom component by referencing the value directly within props.
In the code snippet below, a CustomTip component is imported. That component is then passed to an object where custom components and their associated options are defined.
When using custom components, you must pass an array of components, which is demonstrated by the customComponents variable.
Within your content entry, pass in the custom components with the customComponents prop.
Access the value within the custom component by referencing the value directly within props.
For example, the custom component below, CustomTip, accepts a single input called text.
Access the value within the custom component by referencing the value directly within props.
In the code snippet below, a CustomTip component is imported. That component is then passed to an object where custom components and their associated options are defined.
When using custom components, you must pass an array of components, which is demonstrated by the customComponents variable.
Within your content entry, pass in the custom components with the customComponents prop.
Access the value within the custom component by referencing the value directly within props.
In the code snippet below, a CustomTip component is imported. That component is then passed to an object where custom components and their associated options are defined.
When using custom components, you must pass an array of components, which is demonstrated by the customComponents variable.
Within your content entry, pass in the custom components with the customComponents prop.
Access the value within the custom component by referencing the value directly within props.
For example, the custom component below, CustomTip, accepts a single input called text.
Access the value within the custom component by referencing the value directly within props.
In the code snippet below, a CustomTip component is imported. That component is then passed to an object where custom components and their associated options are defined.
When using custom components, you must pass an array of components, which is demonstrated by the customComponents variable.
Within your content entry, pass in the custom components with the customComponents prop.
Access the value within the custom component by referencing the value directly within props.
For example, the custom component below, CustomTip, accepts a single input called text.
Access the value within the custom component by referencing the value directly within props.
In the code snippet below, a CustomTip component is imported. That component is then passed to an object where custom components and their associated options are defined.
When using custom components, you must pass an array of components, which is demonstrated by the customComponents variable.
Within your content entry, pass in the custom components with the customComponents prop.
Access the value within the custom component by referencing the value directly within props.
In the code snippet below, a CustomTip component is imported. That component is then passed to an object where custom components and their associated options are defined.
When using custom components, you must pass an array of components, which is demonstrated by the customComponents variable.
Within your content entry, pass in the custom components with the customComponents prop.
Access the value within the custom component by referencing the value directly within props.
In the code snippet below, a CustomTip component is imported. That component is then passed to an object where custom components and their associated options are defined.
When using custom components, you must pass an array of components, which is demonstrated by the customComponents variable.
Within your content entry, pass in the custom components with the customComponents prop.
Access the value within the custom component by referencing the value directly within props.
In the code snippet below, a CustomTip component is imported. That component is then passed to an object where custom components and their associated options are defined.
When using custom components, you must pass an array of components, which is demonstrated by the customComponents variable.
Within your content entry, pass in the custom components with the customComponents prop.
Access the value within the custom component by referencing the value directly within props.
In the code snippet below, a CustomTip component is imported. That component is then passed to an object where custom components and their associated options are defined.
When using custom components, you must pass an array of components, which is demonstrated by the customComponents variable.
Within your content entry, pass in the custom components with the customComponents prop.
Access the value within the custom component by referencing the value directly within props.
For example, the custom component below, CustomTip, accepts a single input called text.
Access the value within the custom component by referencing the value directly within props.
In the code snippet below, a CustomTip component is imported. That component is then passed to an object where custom components and their associated options are defined.
When using custom components, you must pass an array of components, which is demonstrated by the customComponents variable.
Within your content entry, pass in the custom components with the customComponents prop.
Access the value within the custom component by referencing the value directly within props.
Within the Visual Editor, you can set the value by clicking on the component and then going to the Options panel. There, change the input's value.
In the video below, the Options panel contains the text state value. When updated, the text within the CustomTip component is updated on the page.
Access custom component state
By creating a custom input, you add user-defined state to a custom component within the Visual Editor. Your custom component will have access to that value as well.
In the video below, a new custom input is created within the Content Inputs panel called calloutText. This input is given a default value of "Tip".
Within your custom component, access the calloutText value by accessing builderState.
This value can be changed within the Data tab under Content State.
In the video below, the calloutText value is changed from "Tip" to "Helpful hint." This changes the display of the custom component.
To access custom inputs, update your custom component's options object to include the shouldReceiveBuilderProps key. The value should be an object with builderContext set to the value true.
Within your custom component, access the calloutText value by accessing builderContext. This object contains another object called rootState, which contains your custom values.
This value can be changed within the Data tab under Content State.
In the video below, the calloutText value is changed from "Tip" to "Helpful hint." This changes the display of the custom component.
Within your custom component, access the calloutText value by accessing builderState.
This value can be changed within the Data tab under Content State.
In the video below, the calloutText value is changed from "Tip" to "Helpful hint." This changes the display of the custom component.
To access custom inputs, update your custom component's options object to include the shouldReceiveBuilderProps key. The value should be an object with builderContext set to the value true.
Within your custom component, access the calloutText value by accessing builderContext. This object contains another object called rootState, which contains your custom values.
This value can be changed within the Data tab under Content State.
In the video below, the calloutText value is changed from "Tip" to "Helpful hint." This changes the display of the custom component.
Within your custom component, access the calloutText value by accessing builderState.
This value can be changed within the Data tab under Content State.
In the video below, the calloutText value is changed from "Tip" to "Helpful hint." This changes the display of the custom component.
To access custom inputs, update your custom component's options object to include the shouldReceiveBuilderProps key. The value should be an object with builderContext set to the value true.
Within your custom component, access the calloutText value by accessing builderContext. This object contains another object called rootState, which contains your custom values.
This value can be changed within the Data tab under Content State.
In the video below, the calloutText value is changed from "Tip" to "Helpful hint." This changes the display of the custom component.
To access custom inputs, update your custom component's options object to include the shouldReceiveBuilderProps key. The value should be an object with builderContext set to the value true.
Within your custom component, access the calloutText value by accessing builderContext. This object contains another object called rootState, which contains your custom values.
This value can be changed within the Data tab under Content State.
In the video below, the calloutText value is changed from "Tip" to "Helpful hint." This changes the display of the custom component.
Within your custom component, access the calloutText value by accessing builderState.
This value can be changed within the Data tab under Content State.
In the video below, the calloutText value is changed from "Tip" to "Helpful hint." This changes the display of the custom component.
To access custom inputs, update your custom component's options object to include the shouldReceiveBuilderProps key. The value should be an object with builderContext set to the value true.
Within your custom component, access the calloutText value by accessing builderContext. This object contains another object called rootState, which contains your custom values.
This value can be changed within the Data tab under Content State.
In the video below, the calloutText value is changed from "Tip" to "Helpful hint." This changes the display of the custom component.
Within your custom component, access the calloutText value by accessing builderState.
This value can be changed within the Data tab under Content State.
In the video below, the calloutText value is changed from "Tip" to "Helpful hint." This changes the display of the custom component.
To access custom inputs, update your custom component's options object to include the shouldReceiveBuilderProps key. The value should be an object with builderContext set to the value true.
Within your custom component, access the calloutText value by accessing builderContext. This object contains another object called rootState, which contains your custom values.
This value can be changed within the Data tab under Content State.
In the video below, the calloutText value is changed from "Tip" to "Helpful hint." This changes the display of the custom component.
To access custom inputs, update your custom component's options object to include the shouldReceiveBuilderProps key. The value should be an object with builderContext set to the value true.
Within your custom component, access the calloutText value by accessing builderContext. This object contains another object called rootState, which contains your custom values.
This value can be changed within the Data tab under Content State.
In the video below, the calloutText value is changed from "Tip" to "Helpful hint." This changes the display of the custom component.
To access custom inputs, update your custom component's options object to include the shouldReceiveBuilderProps key. The value should be an object with builderContext set to the value true.
Within your custom component, access the calloutText value by accessing builderContext. This object contains another object called rootState, which contains your custom values.
This value can be changed within the Data tab under Content State.
In the video below, the calloutText value is changed from "Tip" to "Helpful hint." This changes the display of the custom component.
To access custom inputs, update your custom component's options object to include the shouldReceiveBuilderProps key. The value should be an object with builderContext set to the value true.
Within your custom component, access the calloutText value by accessing builderContext. This object contains another object called rootState, which contains your custom values.
This value can be changed within the Data tab under Content State.
In the video below, the calloutText value is changed from "Tip" to "Helpful hint." This changes the display of the custom component.
To access custom inputs, update your custom component's options object to include the shouldReceiveBuilderProps key. The value should be an object with builderContext set to the value true.
Within your custom component, access the calloutText value by accessing builderContext. This object contains another object called rootState, which contains your custom values.
This value can be changed within the Data tab under Content State.
In the video below, the calloutText value is changed from "Tip" to "Helpful hint." This changes the display of the custom component.
Within your custom component, access the calloutText value by accessing builderState.
This value can be changed within the Data tab under Content State.
In the video below, the calloutText value is changed from "Tip" to "Helpful hint." This changes the display of the custom component.
To access custom inputs, update your custom component's options object to include the shouldReceiveBuilderProps key. The value should be an object with builderContext set to the value true.
Within your custom component, access the calloutText value by accessing builderContext. This object contains another object called rootState, which contains your custom values.
This value can be changed within the Data tab under Content State.
In the video below, the calloutText value is changed from "Tip" to "Helpful hint." This changes the display of the custom component.
Access application state in a custom component
You may also access application state within your custom components. This can be useful, for example, when you want to be able to influence the presentation of a component based on internal values within your application.
When the BuilderComponent below is rendered, the data attribute is set to an object which contains a key called theme and points towards a value that is set by state.
A special property is added to your props, called builderState. This will include state values provided by you in the application and other state values provided to Builder.
When the Content component below is rendered, the data attribute is set to an object which contains a key called theme.
This value is also be accessible withinbuilderContext.rootState.
When the BuilderComponent below is rendered, the data attribute is set to an object which contains a key called theme and points towards a value that is set by state.
A special property is added to your props, called builderState. This will include state values provided by you in the application and other state values provided to Builder.
When the Content component below is rendered, the data attribute is set to an object which contains a key called theme.
This value is also be accessible withinbuilderContext.rootState.
When the BuilderComponent below is rendered, the data attribute is set to an object which contains a key called theme and points towards a value that is set by state.
A special property is added to your props, called builderState. This will include state values provided by you in the application and other state values provided to Builder.
When the Content component below is rendered, the data attribute is set to an object which contains a key called theme.
This value is also be accessible withinbuilderContext.rootState.
When the Content component below is rendered, the data attribute is set to an object which contains a key called theme.
This value is also be accessible withinbuilderContext.rootState.
When the BuilderComponent below is rendered, the data attribute is set to an object which contains a key called theme and points towards a value that is set by state.
A special property is added to your props, called builderState. This will include state values provided by you in the application and other state values provided to Builder.
When the Content component below is rendered, the data attribute is set to an object which contains a key called theme.
This value is also be accessible withinbuilderContext.rootState.
When the BuilderComponent below is rendered, the data attribute is set to an object which contains a key called theme and points towards a value that is set by state.
A special property is added to your props, called builderState. This will include state values provided by you in the application and other state values provided to Builder.
When the Content component below is rendered, the data attribute is set to an object which contains a key called theme.
This value is also be accessible withinbuilderContext.rootState.
When the Content component below is rendered, the data attribute is set to an object which contains a key called theme.
This value is also be accessible withinbuilderContext.rootState.
When the Content component below is rendered, the data attribute is set to an object which contains a key called theme.
This value is also be accessible withinbuilderContext.rootState.
When the Content component below is rendered, the data attribute is set to an object which contains a key called theme.
This value is also be accessible withinbuilderContext.rootState.
When the Content component below is rendered, the data attribute is set to an object which contains a key called theme.
This value is also be accessible withinbuilderContext.rootState.
When the BuilderComponent below is rendered, the data attribute is set to an object which contains a key called theme and points towards a value that is set by state.
A special property is added to your props, called builderState. This will include state values provided by you in the application and other state values provided to Builder.
When the Content component below is rendered, the data attribute is set to an object which contains a key called theme.
This value is also be accessible withinbuilderContext.rootState.
What's next
Read more about binding data within the Data binding overview. To learn how to add more values to state directly from Builder, visit Content inputs.