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
Updating state with checkboxes #2485
Comments
You need to use |
sersorrel
added a commit
to wsi-cogs/frontend
that referenced
this issue
Jul 30, 2019
The problem: if the user clicked on a checkbox in the MultiselectDropDown (rather than clicking on the text adjacent to the checkbox), the state of the checkbox would appear visually to stay the same, but everything else -- its props, the parent element's state, etc. -- correctly believed that the checkbox has been toggled. To fix this, we force an update of the entire component every time a checkbox is clicked, which rerenders the checkbox and results in the visual appearance matching the React/DOM state again. Both the call to setTimeout and the two arrow functions are required; without the arrow functions, various React code doesn't get the correct `this`, and without the setTimeout, it Just Doesn't Work. It's unclear exactly why this works. There are several issues in the React repo and elsewhere describing similar behaviour: facebook/react#2766 facebook/react#3005 facebook/react#3446 react-bootstrap/react-bootstrap#2485 Unfortunately, none of the suggestions made appear to be directly applicable to this situation. This workaround is bad for two reasons: - it's ugly and nonobvious - it forces a rerender of far too many components Nevertheless, it fixes the problem. Closes #1.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looking over the docs, still not sure how to tie my input to my local state.
onChange is being called fined on click, and state is updating with new values, but the checkbox itself never visually shows as checked. Do I need to use inputRef?
The text was updated successfully, but these errors were encountered: