question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] When passing input.onChange(false) component dont rerender

See original GitHub issue

Hello, 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:closed
  • Created 7 years ago
  • Reactions:9
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
shodanukcommented, Sep 28, 2017

Confirmed NOT fixed in 7.0. Still seeing this with 7.04

1reaction
jonathonwalzcommented, Sep 9, 2017

@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 (not undefined), setting the value to false 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)

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found