'modal button shows Maximum update depth exceeded when using useHistory

I have a response button will redirect user to homepage and clear localstorage too but when i click on it , it shows error

Error: Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops.

<div>
<ResponseAlert message={props.errorMsg}/>
</div>

when onclick on responseAlert it runs below onClick -

localstorage.clear()
history.push("/")

but it shows error like below image error message

according to error i am thinking that it is in node_modules somewhere.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source