Skip to content

use_state setter causes re-render when same value is set #2104

@voidpumpkin

Description

@voidpumpkin

Problem
Yew use_state setter causes re-render when same value is set

Steps To Reproduce
Use a use_effect that sets None value to use_state setter when the value already is None

Here is a small repo with the problem:
https://github.com/voidpumpkin/yew-playground/tree/use-state-setter-compare-problem

Expected behavior
Not to re-render

Screenshots
Not the problem but the representation of the example project already running:
error_yew_playground

Guess of how to fix
I think use_state type T would have to implement PartialEq trait.
Then before creating a new pointer to "new" value, it first would check if the value actually changed.
I believe i can try to fix this, just let me know there would be a green light for it.

Environment:

  • Yew version: [master]
  • Rust version: [ 1.55.0,]
  • Target, if relevant: -
  • Build tool, if relevant: -
  • OS, if relevant: -
  • Browser and version, if relevant:-

Questionnaire

  • I'm interested in fixing this myself but don't know where to start
  • I would like to fix and I have a solution
  • I don't have time to fix this right now, but maybe later

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-yewArea: The main yew cratebug

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions