Skip to content
Discussion options

You must be logged in to vote

there are two well supported ways of approaching this:

1. Use a computed var

Define an @rx.var method in your state that performs the needed filtering. Whenever the data or the filter criteria change, the computed var will be recalculated automatically.

class TargetState(rx.State):
    _target_submissions: list[Dict] = []

    @rx.var
    def filtered_submissions(self) -> list[dict]:
        return {s for s in self._target_submissions if s.get("active")}

...

def index():
    return rx.vstack(
        rx.foreach(TargetState.filtered_submissions, lambda s: submission_card(submission=s)),
    )

This is preferable, because you can make your unfiltered data var a backend-only var (leading un…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@aputhuraya
Comment options

Answer selected by aputhuraya
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants