reflex
reflex copied to clipboard
Foreach Unexpected Index
Describe the bug Foreach seems to be using the index even when not specified.
To Reproduce Steps to reproduce the behavior:
- Code/Link to Repo:
-
class ForeachState(pc.State): color = [ "red", "green", "blue", "yellow", "orange", "purple", ]
def colored_box(color): return pc.box(pc.text(color), bg=color)
def index(): return pc.responsive_grid( pc.foreach(ForeachState.color, colored_box), columns=[2, 4, 6], )
**Expected behavior**
A clear and concise description of what you expected to happen.
The text should have the color name instead it used the index.
**Screenshots**
If applicable, add screenshots to help explain your problem.
** Specifics (please complete the following information):**
- Python Version: 3.11
- Pynecone Version: 0.1.13
- OS: Mac
- Browser (Optional):
Hey, I want to contribute to this issue. Can you please tell me in which folder/directory I'll get this code?
Thanks for the help!
These are the two relevant files: https://github.com/pynecone-io/pynecone/blob/main/pynecone/components/tags/iter_tag.py#L50 https://github.com/pynecone-io/pynecone/blob/2a5ed7d40bb59e6759f8f37cc956b5faaf732853/pynecone/components/layout/foreach.py#L11
This may be a bit difficult to start without understanding how the compiler works. I'm working on a detailed blog post that should help give an overview. In the meanwhile, happy to help discuss and guide you through it on our Discord!
The given code works fine on my computer. What is the actual problem?
Yeah this seems to work for me too - let's close this until we can reproduce.