reflex icon indicating copy to clipboard operation
reflex copied to clipboard

Foreach Unexpected Index

Open Alek99 opened this issue 2 years ago β€’ 3 comments

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):
 

Alek99 avatar Jan 21 '23 23:01 Alek99

Hey, I want to contribute to this issue. Can you please tell me in which folder/directory I'll get this code?

SoumyadeepOSD avatar Jan 22 '23 17:01 SoumyadeepOSD

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!

picklelo avatar Jan 22 '23 18:01 picklelo

The given code works fine on my computer. What is the actual problem?

erkamkavak avatar Jan 23 '23 10:01 erkamkavak

Yeah this seems to work for me too - let's close this until we can reproduce.

picklelo avatar Jan 28 '23 23:01 picklelo