import { StatusBar } from 'expo-status-bar';
import React from 'react';
import { StyleSheet, Text, View,Button } from 'react-native';
export default function App() {
handle()
{
console.log("pressed");
}
return (
<View style={styles.container}>
<Text>HEllo World!</Text>
<Button variant="outlined" title = " hello" onPress={handle}></Button>
<StatusBar style="auto" />
</View>
);
}
const st
yles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
我只是尝试在按下按钮时在控制台中打印一些文本。
只需将其更改为:
function handle()
{
console.log("pressed");
}
然后:
onPress={()=>handle()}