Skip to content

Commit 9f83b65

Browse files
committed
[ENG-4570] Iterate over ObjectVar.entries
1 parent 27a745b commit 9f83b65

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

reflex/.templates/jinja/web/pages/utils.js.jinja2

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
{# Args: #}
6161
{# component: component dictionary #}
6262
{% macro render_iterable_tag(component) %}
63-
<>{ {%- if component.iterable_type == 'dict' -%}Object.entries({{- component.iterable_state }}){%- else -%}{{- component.iterable_state }}{%- endif -%}.map(({{ component.arg_name }}, {{ component.arg_index }}) => (
63+
<>{ {{ component.iterable_state }}.map(({{ component.arg_name }}, {{ component.arg_index }}) => (
6464
{% for child in component.children %}
6565
{{ render(child) }}
6666
{% endfor %}

reflex/components/core/foreach.py

+5
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ def create(
5454
TypeError: If the render function is a ComponentState.
5555
UntypedVarError: If the iterable is of type Any without a type annotation.
5656
"""
57+
from reflex.vars.object import ObjectVar
58+
5759
iterable = LiteralVar.create(iterable)
5860
if iterable._var_type == Any:
5961
raise ForeachVarError(
@@ -70,6 +72,9 @@ def create(
7072
"Using a ComponentState as `render_fn` inside `rx.foreach` is not supported yet."
7173
)
7274

75+
if isinstance(iterable, ObjectVar):
76+
iterable = iterable.entries()
77+
7378
component = cls(
7479
iterable=iterable,
7580
render_fn=render_fn,

0 commit comments

Comments
 (0)