lundi 28 décembre 2020

React Native Alert.alert() only works on iOS and Android not web

I just started learning and practicing React Native and I have run into the first problem that I cant seem to solve by myself.

I have the following code, which is very simple, but the Alert.alert() does not work when I run it on the web. if I click the button nothing happens, however, when i click the button on an iOS or android simulator it works fine.

import { StatusBar } from 'expo-status-bar';
import React from 'react';
import { StyleSheet, Text, Button, View, Alert } from 'react-native';

export default function App() {
  return (
      <View style={styles.container}>
        <Text style={styles.headerStyle} >Practice App</Text>
        <Text style=>Open up App.js to start working on your app!</Text>
        <Button
          onPress={() => alert('Hello, Nice To Meet You  :)')}
          title="Greet Me"
        />
        <StatusBar style="auto" />
      </View>
  );
}

I also know that alert() works on all three devices, however, I want to understand why Alert.alert() only works for iOS and Android.

My question is more so for understanding rather than finding a solution. Is the only solution to use alert(), or am I implementing Alert.alert() in the wrong way?




Aucun commentaire:

Enregistrer un commentaire