Skip to content

Is it safe to ignore some properties from PartialEq for a struct component. #3739

Answered by WorldSEnder
zstewar1 asked this question in Q&A
Discussion options

You must be logged in to vote

Yew compares with the existing props and only replaces if they compare unequal. In this case, changed is then called to figure out if the component needs to re-render. Note that this callback also gives you access to the old props. So the correct way to avoid a re-render is to implement changed here.

Small comment about the concern about duplicating work: The relevant code section is monomorphized per component, so I would think that the compiler is smart enough to inline changed in most cases and remove the duplicate checks in a lot of cases.

Relevant code:

if self.context.props != props {
let o…

Replies: 1 comment 2 replies

Comment options

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

@WorldSEnder
Comment options

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