I've found some thread about this problem, but none of them solved mine.
Can't call setState on a component that is not yet mounted. This is a no-op, but it might indicate a bug in your application.
Can't call setState on a component that is not yet mounted
React app. Can't call setState on a component that is not yet mounted
import React, { Component } from 'react';
import { Card, CardHeader, CardBody, Button, Collapse } from 'reactstrap';
class MyComponent extends React.Component<any, any> {
constructor(props) {
super(props);
this.toggle = this.toggle.bind(this);
this.state = {
collapse: false,
};
}
toggle() {
this.setState({ collapse: !this.state.collapse });
}
render() {
return (
<Card>
<CardHeader>
<Button color="link" onClick={this.toggle} className="float-right">
Click me to toggle collapse
</Button>
</CardHeader>
<Collapse isOpen={this.state.collapse}>
<CardBody>
The content being collapsed
</CardBody>
</Collapse>
</Card>
);
}
}
export default MyComponent;
- If i put in
componentDidMount() { console.log("Mounted!"); }
then sure, it still appear in the console window. - I've tried answers from similar threads such as install babel polyfill, delete react-hot-loader, but none of them works.
- I get this problem in every components I have setState and a button (or something similar) to call the method.
- Anyone have the idea to fix? I appreciate every of them. Many thanks