I have a simple clear button in my render method
<Button onClick={this.clearFilters(data)}> CLEAR </Button>
that calls function that clears out a state
clearFilters(data){
if (!data || !this.state) {
return;
}
const blankFilter = '';
this.setState({
filter: blankFilter });
}
But if I add the setState line I got a ton of warnings and it pretty well freezes up.
Warning: Cannot update during an existing state transition (such as within render
or another component's constructor). Render methods should be a pure function of props and state; constructor side-effects are an anti-pattern, but can be moved to componentWillMount
How can I implement this in componentWillMount?