Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

alert for both android and IOS in react-native

Tags:

react-native

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

  • AlertIOS is working in IPhone but not working in android and alert also same In Docs i saw that Alert.alert will work for both Android an IOS,But i got an error like undefined is not an object(evaluating 'Alert.alert') I wrote like this:
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

like image 746
Hussian Shaik Avatar asked Feb 18 '16 05:02

Hussian Shaik


People also ask

Does alert work in React Native?

The Alert API efficiently works on both iOS and Android and can show static alerts. React Native offers three types of Alert dialog, and those are Simple Alert, Two Options Alert, and Three Options Alert.

How do you show success message in React Native?

Show some messageshowMessage({ message: "Hello World", description: "This is our second message", type: "success", }); The type attribute set the type and color of your flash message, default options are "success" (green), "warning" (orange), "danger" (red), "info" (blue) and "default" (gray).


1 Answers

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';
like image 146
Gergo Bogdan Avatar answered Oct 22 '22 05:10

Gergo Bogdan