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.

warning setstate(...) can only update a mounted or mounting component on RadioButton

See original GitHub issue

Based on the change radio button option, I hide/show other radio buttons, I do this by maintaining flags in state. I’m not holding any reference to the radio button. When I hide and show multiple times, I’m getting the following error. May be the componentWillUnmount should be handled in RadioButton.js?

warning setstate(…) can only update a mounted or mounting component. This means you called setState on an unmounted component. This is a no-op. please check the RadioButton component

Sample Code:

ona3Change({ checked }) {
    const newState = {
      isPPPP: checked,
    };
    if (checked === false) {
      newState.isUUUU = null;
      newState.isJJJJ = null;
    }
    this.setState(newState);
  }


//On render
{this.state.isPPPP === false ?
          <View>
            <Text style={styles.label}>some question??????</Text>
            <View style={styles.row}>
              <MKRadioButton
                group={this.ddGroup}
                onCheckedChange={this._ona1Change}
              />
              <Text style={styles.text}>
                Yes
              </Text>
              <MKRadioButton
                group={this.ddGroup}
              />
              <Text style={styles.text}>
                No
              </Text>
            </View>
          </View>
          : null
        }
        {this.state.isUUUU === false ?
          <View>
            <Text style={styles.label}>HHHHH</Text>
            <View style={styles.row}>
              <MKRadioButton
                group={this.aa2RadioGroup}
                onCheckedChange={this._ona3Change}
              />

              <Text style={styles.text}>
               ggggggg
              </Text>
            </View>
            <View style={styles.row}>
              <MKRadioButton
                group={this.aa2RadioGroup}
                onCheckedChange={this._ona3Change}
              />
              <Text style={styles.text}>
                dddddd
              </Text>
            </View>
          </View>
        : this.state.isJJJJ === true ?
          <View>
            <Text style={styles.label}>
              ffffff
            </Text>
            <TextInput
              placeholder="Name"
              style={styles.text}
              placeholderTextColor={theme.placeholderTextColor}
            />
          </View>
          : null
      }

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:2
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
ghostcommented, Aug 13, 2016

+1 @ananddayalan I’m also getting the same error. Did you find a solution for it?

0reactions
JulianKingmancommented, Mar 27, 2017

Just to add, I still get the error, but at least it works.

Read more comments on GitHub >

github_iconTop Results From Across the Web

javascript - React Warning: Can only update a mounted or ...
Warning : Can only update a mounted or mounting component. This usually means you called setState, replaceState, or forceUpdate on an unmounted  ......
Read more >
Warning: setState(...): Can only update a mounted or ... - GitHub
"Warning: setState(...): Can only update a mounted or mounting component. This usually means you called setState() on an unmounted component. This is a...
Read more >
Uncontrolled Components - React
In a controlled component, form data is handled by a React component. The alternative is uncontrolled components, where form data is handled by...
Read more >
Warning about calling setState on an unmounted component ...
To avoid this, check if the component is mounted before setting state in that component. Use a flag to check, say this.mounted =...
Read more >
How to Use Radio Buttons in ReactJS | Pluralsight
In this guide, you'll learn the basics of the radio button, how to use it in a group, ... and the value is...
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