Components

/

Conditional-props

Sometimes you want to set a prop based on a condition. You can use the rx.cond function to do this.

class PropCondState(rx.State):
    value: list[int]

    def set_end(self, value: int):
        self.value = value


def cond_prop():
    return rx.slider(
        default_value=[50],
        on_value_commit=PropCondState.set_end,
        color_scheme=rx.cond(
            PropCondState.value[0] > 50, "green", "pink"
        ),
        width="100%",
    )

Did you find this useful?

Raise an issue

Links

HomeShowcaseBlogChangelog

Join Newsletter

Get the latest updates and news about Reflex.

Copyright © 2024 Pynecone, Inc.