'React Native (0.63) Alert disappear automatically in IOS
I am using RN 0.63 and i am facing issue in React Native core alert.It popup and disappear automatically with second.I want alert should disappear when i click on OK button.
Alert.alert(
'Alert Title',
msg, // <- this part is optional, you can pass an empty string
[
{text: 'OK', onPress: () => console.log('OK Pressed')},
],
{cancelable: false},
);
Solution 1:[1]
I ran into the same issue and was able to avoid the "automatically disappearing" Alert popup after finding a loading
prop was being passed down into a child component and was being (unnecessarily, in my case) consumed.
So I resolved the issue by simply removing the prop and handling the "loading" logic in the parent component.
Please double check that there are no unintentional re-renders of your component that may cause the Alert to be dismissed.
Solution 2:[2]
Probably you are showing dialog right after setState. You need to show dialog once the state update is completed. If this is not doable, it's not a good idea but a workaround then simply wrap dialog within setTimeout.
setTimeout(() => {
Alert.alert(
"Title",
"Message",
[
{
text: "OK",
onPress: () => {},
},
],
{ cancelable: false }
);
}, 100);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Tony Xu |
Solution 2 | Sabri MeviÅŸ |