采纳答案成功!
向帮助你的同学说点啥吧!感谢那些助人为乐的人
实在是不知道为什么模拟器onPress后打印不出来log
/** * Sample React Native App * https://github.com/facebook/react-native * * @format */ import React, {useState} from 'react'; import {SafeAreaView, StatusBar, StyleSheet, View, TouchableOpacity, Text} from 'react-native'; function App(): React.JSX.Element { const [count, setCount] = useState(0); const onPress = () => { console.log('test'); setCount(prevCount => prevCount + 1); }; return ( <View> <View style={styles.container}> <View style={styles.countContainer}> <Text>Count: {count}</Text> </View> <TouchableOpacity style={styles.button} onPress={onPress}> <Text>Press Here</Text> </TouchableOpacity> </View> </View> ); } const styles = StyleSheet.create({ container: { width: '100%', height: '100%', flexDirection: 'column', alignItems: 'center', backgroundColor: 'white', }, button: { alignItems: 'center', backgroundColor: '#DDDDDD', padding: 10, }, countContainer: { alignItems: 'center', padding: 10, }, }); export default App;
copy了个官方例子, 然后放到app里试了,也不行,难道模拟器的事情?
"react": "18.2.0", "react-native": "0.73.6"
Unable to dispatch touch to JS as the catalyst instance has not been attached
登录后可查看更多问答,登录/注册
30+小案例+2个实战项目,快人一步提升个职业竞争力
916 2
839 16
998 15
994 12
796 7
购课补贴联系客服咨询优惠详情
慕课网APP您的移动学习伙伴
扫描二维码关注慕课网微信公众号