Replies: 2 comments 2 replies
-
You can define custom vars by subclassing Try this: class SourceFile(rx.Base):
file_name: str
file_marker: bool
# This is only needed if you don't want to specify the fields as keyword args, otherwise the above^ is enough
def __init__(self, file_name: str, file_marker: bool):
super().__init__(file_name=file_name, file_marker=file_marker)
class UploadState(rx.State):
files: list[SourceFile] = [SourceFile("file1", True), SourceFile("file2", False)] Then in your frontend rx.foreach(
UploadState.files,
lambda file, index: rx.text(file.file_name) # This should work now :)
) |
Beta Was this translation helpful? Give feedback.
0 replies
-
Thank you! This is really helpful! Unfortunately, this is still not working for import reflex as rx
class File(rx.Base):
name: str
icon: str = "file"
class FileState(rx.State):
files: list[File] = [File(name="file1"), File(name="file2")]
def index() -> rx.Component:
return rx.foreach(
FileState.files,
lambda file, index: rx.box(
rx.icon(file.icon),
rx.text(file.name),
)
)
app = rx.App()
app.add_page(index) The string with
If i change this to
reflex==0.4.6 |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello! I am trying to use my own class inside State like this:
The problem here is that I can't access these fields from
rx.foreach
.I understand that it would be quite naive to assume that I can simply access this field, since Var knows nothing about custom objects.
I tried to dig into
Var
,BaseVar
andForeach
, but my experience is not enough to find the place where everything breaks.At the same time, it is completely unclear how to connect the pyCharm debugger to the
reflex run
process (the web server does not start, nothing works)...Would be nice if you have some solution for my approach..
Beta Was this translation helpful? Give feedback.
All reactions