Skip to content

How to avoid rerendering when matching on an enum #2079

Answered by gbj
j4ger asked this question in Q&A
Discussion options

You must be logged in to vote

I need to render a component based on a state enum that is synced from the backend via websockets

I just want to start by acknowledging that there are pain points with this kind of scenario and fine-grained reactivity, so don't feel like you're doing anything wrong if it's a little painful. Signals work really well when your local interactions are what's driving state, but relatively less well with a big glob of global state, especially when it comes from an external source.

That said, it's achievable.

I'd recommend a memo that just toggles back and forth between the two modes:

#[component]
fn GameView(state: Signal<State>) -> impl IntoView {
    let in_game = create_memo(move |_| matches!

Replies: 1 comment 1 reply

Comment options

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

Answer selected by j4ger
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