Q: react-native alert error "Attemp to present UIAlertController In my react-native application i use some alerts to display messages to the user.
On android everything works fine, but in ios i get following error, every time i try to display an alert:
Warning: Attempt to present <UIAlertController: 0x1030fb600> on <RCTModalHostViewController: 0x1021ad720> whose view is not in the window hierarchy!

i call the alert message via:
this.setState({spinner: true}, () => {
  eventHandler
    .joinEventById(eventCode, qrHash)
    .then((response) => {
      this.setState({spinner: false}, () => {
        Toast.show('Event Registrierung erfolgreich');
      });
    })
    .catch((error) => {
      this.setState({spinner: false}, () =>
        funcHelper.showAlert('Fehler beim Beitritt', error, null),
      );
    });
});

i found some solutions to fix it but only for native code, not for the react version.
Can someone give me a hint how i cant fix this or whats the reason for this error

A: It happened to me when there was a loader. For example, when trying to login, the loader is displayed by setting a variable false in state. When there is a failure, the state for displaying the loader is set to false and Alert is immediately displayed. It turns out that useState is asynchronous and if Alert was called before the loader disappeared, the error occurred.

A: Use workaround solution with setTimeout in 300 miliseconds.
this.setState({spinner: false}, ()=>{
        setTimeout(()=>{
          Toast.show('Event Registrierung erfolgreich');
        }, 300)
        
      });

