[BUG] When passing input.onChange(false) component dont rerender
See original GitHub issueHello,
Found a bug with input.onChange(false)
: it doesn’t rerender.
I create a Custom Field who create a group of buttons to mirror the behaviour of radio true/false but with buttons :
<Field
component={DefaultGroupedButton}
name="user.statut"
required
label="Question ?"
elements={[
{
label: 'Yes',
value: true
},
{
label: 'No',
value: false
}
]}/>
and in DefaultGroupedButton
i map each elements with a button and it’s value.
When i click on one of the button i call onChange with the value in element (can be true
or false
) :
const onChange = (e, data) => {
// if i click again in the same button i want to remove the value so i pass null
if (input.value === data.value) {
console.log('changing to null');
input.onChange(null)
}
else {
console.log('changing to ' , data.value);
input.onChange(data.value);
}
};
It’s working great with true
.
But with false
the component don’t rerender. I see it change in redux but their is no rerender so i can’t apply display condition in other element.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:9
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Input not re-rendering onChange with hooks
When I conditionally tried to render them as components <TaskText/> and <TaskInput/>, the onClick event stopped working, but react rendered < ...
Read more >5 Ways to Avoid React Component Re-Renderings
1. Memoization using useMemo() and UseCallback() Hooks. Memoization enables your code to re-render components only if there's a change in the props. With...
Read more >input checkbox not updating after re-render #13477
When checking the checkbox, the state changes to false. But the checkbox checked is from the state (true). The parent cannot pass down...
Read more >Controller | React Hook Form - Simple React forms validation
React Hook Form embraces uncontrolled components and native inputs, ... Calling onChange with undefined is not valid. ... error for this specific input....
Read more >A Story of a React Re-Rendering Bug - Engineering Blog
When we find a bug, no matter how tricky it is, it means something is wrong in the code. There is no magic,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Confirmed NOT fixed in 7.0. Still seeing this with 7.04
@gustavohenke both this and #2978 are not solved with the 7.0 release. The issue here is that the comparison is considering null/‘’/false to all be the same. So if the initial value is
null
(notundefined
), setting the value tofalse
isn’t detected as a change.I’ve worked around this by using a string constant for false in the form, but it was definitely unexpected behavior to me. (My use case was a similar to this, a yes/no/no-response style question)