Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checkbox state persists even after re-rendering of Component #298

Closed
chiragmongia opened this issue Sep 9, 2016 · 6 comments
Closed

Checkbox state persists even after re-rendering of Component #298

chiragmongia opened this issue Sep 9, 2016 · 6 comments

Comments

@chiragmongia
Copy link

chiragmongia commented Sep 9, 2016

Earlier, I thought the behavior is same in React, so I asked a question on stackoverflow to clear my doubts. The question clearly explains what the exact problem is. The jsfiddles in the question and answer should help.

But with the answer, it seems React has key attribute to make it work. When I tried the same using Preact, it didn't solve my problem
How can it be done in Preact? Or is this an issue with preact?

PS- I'm not really sure if this belongs to preact or preact-compat, so I'm posting it here.
@developit

@developit
Copy link
Member

Looks like it's due to the element recycling. I had thought there was an older issue where we adressed this, but maybe not!

@chiragmongia
Copy link
Author

@developit No labels on the issue? 😕
Does this need a fix?

@developit
Copy link
Member

Sorry, just working on a regression right now (#297). Can't really prioritize anything else until that's fixed.

In the SO question you linked to, someone suggested using a Controlled Component, which I would suggest is the best workaround for now. Using keys to forcibly reset the DOM is a hack - instead, it's better to tell preact/react what you want the DOM to look like ("the checked value of this input should be true") on every render, using state to drive the UI.

@chiragmongia
Copy link
Author

chiragmongia commented Sep 9, 2016

@developit Yes, right. I have followed the same approach and resolved my problem (thanks to the answer on SO question 😄 )
This is not a blocker for me. Apologies if I bothered you. Please complete your current tasks and you can come back later and prioritize this one.
It's just that I was interested in seeing how this would be fixed in preact. Or rather, I would be happy to help if you guide me on how this can be fixed 😄

@developit
Copy link
Member

This may be related to / solved by a solution to #326

@developit
Copy link
Member

@chiragmongia I believe this should be fixed, or at least any diff inaccuracy should be fixed as a result of #326.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants