Igor
April 30, 2020, 6:48pm
1
{
'@type': '@builder.io/sdk:Element',
component: {
name: 'Button', options: {
children: {
'@type': '@builder.io/sdk:Element',
component: { name: 'Text', options: { text: 'Call To Action' } }
},
href: '#'
}
}
}
how do this ?
aziz
April 30, 2020, 11:38pm
2
To clarify, you have a custom comoponent called Button that has the canHaveChildren set to true and you want to use it as part of the defaultChildren for another custom component?
If so, try to pass the children as an array
Edit: pass children as an array to the element instead.
defaultChildren: [ {
'@type': '@builder.io/sdk:Element',
children: [{
'@type': '@builder.io/sdk:Element',
component: { name: 'Text', options: { text: 'Call To Action' } }
}],
component: {
name: 'Button',
options: {
href: '#'
}
}
}]
Also make sure to use the provider HOC withChildren as in this example
import { Builder, withChildren } from '@builder.io/react';
import { HeroWithEditableChildren } from './HeroWithChildren';
// This line is very important! :)
const HeroWithBuilderChildren = withChildren(HeroWithEditableChildren);
Builder.registerComponent(HeroWithBuilderChildren, {
name: 'Hero With Children',
inputs: [
{
name: 'image',
type: 'file',
allowedFileTypes: ['jpeg', 'jpg', 'png', 'svg'],
required: true,