<Button onPress={{() => Alert.alert( 'Alert Title', 'alertMessage', [ {text: 'Cancel', onPress: () => console.log('Cancel Pressed!')}, {text: 'OK', onPress: () => {this.onDeleteBTN}}, ], { cancelable: false } )}} > <Text> Delete Record </Text> </Button>
After OK button on Alert Dialog I need to call
onDeleteBTN = () => { alert(' OnDelete'); }
{text: 'OK', onPress: () => {this.onDeleteBTN.bind(this)}}, {text: 'OK', onPress: () => {this.onDeleteBTN}},
It's not work
Example: Call a Function After Clicking a Buttonimport React from 'react'; function App() { function sayHello() { alert('Hello!' ); } return ( <button onClick={sayHello}> Click me!
The onPress event is called when user touch or press the Text component. To Set onPress onClick on Text in React Native we have to use onPress={} prop in react native. The onPress event is supported by both Android and iOS platforms.
Tapping any button will fire the respective onPress callback and dismiss the alert. By default, the only button will be an 'OK' button. This is an API that works both on Android and iOS and can show static alerts. Alert that prompts the user to enter some information is available on iOS only.
Pressing the button will call the "onPress" function, which in this case displays an alert popup. If you like, you can specify a "color" prop to change the color of your button.
First issue, the Button
component has a title
prop instead of having <Text>
as a child. Second issue is that you have a bunch of syntax errors and are not calling functions (or binding) correctly. If you fix that, then it should work fine; for example:
alert = (msg) => { console.log(msg) } onDeleteBTN = () => { this.alert(' OnDelete') } render() { return ( <View style={styles.container}> <Button title="Delete Record" onPress={() => Alert.alert( 'Alert Title', 'alertMessage', [ {text: 'Cancel', onPress: () => console.log('Cancel Pressed!')}, {text: 'OK', onPress: this.onDeleteBTN}, ], { cancelable: false } )} /> </View> ); }
Note:
alert()
function is supposed to do, so I made a dummy one that logs to console.onDeleteBTN()
or binding. If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With