I have a main component which is calling another component with some props.
// Main Component
<AnotherComponent
className="EnterNumber-input"
submitClicked={this.state.submitClicked}
/>
On click of a button, I'm changing the state (this.state.submitClicked).
<button
onClick={async () => {
await this.setState({submitClicked : !this.state.submitClicked});
}}
>
Toggle SubmitClicked
</button>
In the other component, I'm comparing the prevState with this.props to show an alert.
componentDidUpdate = (prevProps) => {
if (this.props.submitClicked && this.props.submitClicked !== prevProps.submitClicked) {
alert('This alert is being called on alternate changes');
}
};
Problem- This alert is visible on alternate button clicks.
Requirement- The alert should appear with every button click.