Handle alerts correctly on web in Button example#4946
Conversation
✅ Deploy Preview for react-native ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Hi 👋 |
Simek
left a comment
There was a problem hiding this comment.
Hey @yash04577, thanks for the correction! 👍
Just two things:
Sure |
Hi @Simek , I'm hitting the no-alert linting error in my code example. Since Alert.alert() doesn't show a visual popup on the Web/Snack player, how would you prefer I handle user feedback? Should I use React state to show text in the UI Thanks |
|
The best approach might be to disable the problematic linting rule in the examples lint package ESLint config, since falling back to browser native alert for web seems like the proper thing to do. |
|
@Simek I have done the required changes |
Simek
left a comment
There was a problem hiding this comment.
Thanks for the follow up, LGTM! 👍
Problem
The Button component examples in the docs did not display alerts correctly on web.
Alert.alert()does not show any message.Alert.alert()works as expected.Reproduction Steps (Before Fix)
Old Behavior (Buggy)
onPresshandlers usedAlert.alert()regardless of platform.New Behavior (Fixed)
Alerts now display correctly on all platforms:
window.alert()Alert.alert()Users copying the example now see the expected alert immediately when pressing buttons.
Root Cause
Alert.alert()is not supported in browser environments.Fix