Reflex Logo

Intro

Gallery

Hosting

Components

New

Learn

Components

API Reference

Onboarding

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%",
    )
← Style PropsConditional Rendering →

Did you find this useful?

HomeGalleryChangelogIntroductionHosting