I need to create a component that will render multiple node containers inside. How can I do that? #53
-
I want to create a component with four node containers inside, but I couldn't find any specific examples on websites. I have the configuration code below, but it always renders only one node container. I want to initialize it with four containers, as in the example. Is there any way to achieve this?
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 8 replies
-
If you need four containers that you want to display in different parts of the component, you can describe four properties. I think the example will make it clear: import {define, node, nodeArray, useBuilderContext} from '@react-form-builder/core'
import type {ReactNode} from 'react'
interface FourProps {
one?: ReactNode
two?: ReactNode[]
three?: ReactNode
four?: ReactNode
}
const Four = (props: FourProps) => {
const context = useBuilderContext()
// You can show different components in builder and view modes
const two = context.builderMode === 'builder'
? props.two
: props.two && props.two.length && props.two[0]
return <div>
<div>
<h1>One</h1>
{props.one}
</div>
<div>
<h1>Two</h1>
{two}
</div>
<div>
<h1>Three</h1>
{props.three}
</div>
<div>
<h1>Four</h1>
{props.four}
</div>
</div>
}
export const fourComponent = define(Four, 'Four')
.name('Four')
.props({
one: node, // ReactNode instance will be passed to the component
two: nodeArray, // ReactNode array will be passed to the component
three: node,
four: node,
}) |
Beta Was this translation helpful? Give feedback.
If you need four containers that you want to display in different parts of the component, you can describe four properties. I think the example will make it clear: