Hussian Shaik
Hussian Shaik

Reputation: 2685

alert for both android and IOS in react-native

Hai i am trying to show alert message, i tried different ways like alert,AlertIOS,Alert.alert

Alert.alert('Alert', 'email is not valid, Please enter correct email', [{text: 'Ok'}]);

I got an error like this:

enter image description here

Any one give suggestions that how to show the alert in Android and IOS in react-native Any help much appreciated

Upvotes: 7

Views: 12307

Answers (3)

Sultan Ali
Sultan Ali

Reputation: 2589

I think you forget to import Alert from react-native

import { Alert } from 'react-native';

and then you can show Alert like this

Alert.alert("Alert message");

Upvotes: 3

jayad aadrit
jayad aadrit

Reputation: 359

We just need to import it correctly:

import { Alert } from 'react-native';

Then use it in your project as written in your code and it will work for both platforms :

Alert.alert('Alert', 'email is not valid, Please enter correct email', [{text: 'Ok'}]);

refer: https://facebook.github.io/react-native/docs/alert

Upvotes: 0

Gergo Bogdan
Gergo Bogdan

Reputation: 199

Are you sure you are including it from the correct path? I get the same error when I imported Alert from react library and NOT react-native.

so the working thingie is:

import React, { Component } from 'react';
import { View, Alert } from 'react-native';

and the non-working one was:

import React, { Component, Alert } from 'react';
import { View } from 'react-native';

Upvotes: 18

Related Questions