How to set alert box title in React-Native's a

2020-03-10 22:49发布

问题:

I cannot set the title of an Alert box with React-Native

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

...

alert("myTitle","my message");

Title shows as "Alert" instead of as "myTitle"

回答1:

The syntax is different:

Alert.alert("myTitle", "my message");

Reference: http://facebook.github.io/react-native/docs/alert.html#examples



回答2:

 Alert.alert(
        'Alert Title',
        'My Alert Msg',
        [
          {text: 'Ask me later', onPress: () => console.log('Ask me later pressed')},
          {text: 'Cancel', onPress: () => console.log('Cancel Pressed'), style: 'cancel'},
          {text: 'OK', onPress: () => console.log('Ok Pressed')},
        ],
        { cancelable: false }
      )