warning setstate(...) can only update a mounted or mounting component on RadioButton
See original GitHub issueBased 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:
- Created 7 years ago
- Reactions:2
- Comments:6 (1 by maintainers)
Top 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 >
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 Free
Top 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
+1 @ananddayalan I’m also getting the same error. Did you find a solution for it?
Just to add, I still get the error, but at least it works.