From 1bb40e399bd3f751fb751e4ba7b411402c2c7f22 Mon Sep 17 00:00:00 2001 From: johndoe6345789 Date: Sun, 18 Jan 2026 02:05:42 +0000 Subject: [PATCH] Fix loop rendering to use children context --- src/lib/json-ui/renderer.tsx | 55 ++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 28 deletions(-) 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)} ) }