diff --git a/src/lib/json-ui/renderer.tsx b/src/lib/json-ui/renderer.tsx index c52e48d..3dab3ae 100644 --- a/src/lib/json-ui/renderer.tsx +++ b/src/lib/json-ui/renderer.tsx @@ -25,6 +25,27 @@ export function JSONUIRenderer({ } } + const renderChildren = ( + children: UIComponent[] | string | undefined, + renderContext: Record + ) => { + if (!children) return null + + if (typeof children === 'string') { + return children + } + + return children.map((child, index) => ( + + )) + } + if (component.loop) { const items = resolveDataBinding(component.loop.source, dataMap) || [] return ( @@ -36,14 +57,10 @@ export function JSONUIRenderer({ ...(component.loop!.indexVar ? { [component.loop!.indexVar]: index } : {}), } return ( - - )} + + {renderChildren(component.children, loopContext)} + + ) })} ) @@ -87,31 +104,13 @@ export function JSONUIRenderer({ props.style = { ...props.style, ...component.style } } - const renderChildren = () => { - if (!component.children) return null - - if (typeof component.children === 'string') { - return component.children - } - - return component.children.map((child, index) => ( - - )) - } - if (typeof Component === 'string') { - return React.createElement(Component, props, renderChildren()) + return React.createElement(Component, props, renderChildren(component.children, context)) } return ( - {renderChildren()} + {renderChildren(component.children, context)} ) }