Skip to content

How to render optional props simply? #2240

Answered by voidpumpkin
duskmoon314 asked this question in Q&A
Discussion options

You must be logged in to vote

@duskmoon314 in your case i would just do

#[derive(PartialEq)]
enum SquareValue {
    X,
    O,
}

#[derive(Properties, PartialEq)]
struct SquareProps {
    value: Option<SquareValue>,
}
    html! {
        <button class="square" onclick={on_click}>{ value.unwrap_or("") }</button>
    }

Replies: 2 comments 3 replies

Comment options

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

Comment options

You must be logged in to vote
2 replies
@duskmoon314
Comment options

@voidpumpkin
Comment options

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