export const Focus = ({addSubject})=>{

const [tempValue, setTempValue] = useState(null);

  return(
    <View style={styles.container}> 
     <View style={styles.titleContainer}> 
    <Text style={styles.title}> What are you going to focus on....?</Text>
     <View style={styles.inputcontainer}> 
    <TextInput style ={{flex:1, marginRight:10}}  
    onSubmitEditing ={
      ({nativeEvent}) => {
        setTempValue(nativeEvent.text+'0000')
      }
    }
    />
       <RoundedButton title ='+' onPress={
         addSubject(tempValue) 
         }/> 
        
       </View>
     </View>
    </View>
  );
}

就在输入数据之后,一旦点击‘Return’,提交就输入了"Text+0000"

但一旦替换为

 <RoundedButton title ='+' onPress={
         ()=>{ addSubject(tempValue)}
         }/>

在印刷机上不起作用

*我正在expo 网站上测试

出现这种行为的原因是什么?按下按钮后有什么解决方案使其工作.

推荐答案

try 不带大括号,则只有它会返回addSubject函数

<RoundedButton 
  title ='+' 
  onPress={()=> addSubject(tempValue)}
/> 

React-native相关问答推荐

AWS Amplify处理后端错误

React-Native:请纠正我对状态如何工作的误解 - 动态文本输入

如何根据设备主题更改React Native中状态栏的背景?

无法解析 com.google.gms:google-services:4.3.15

如何在react-native 的switch 内显示文本(是/否)

如何在 React Native 中正确地将组件导入到我的导航器中?

React Native Child Parent 通信

React Native React 导航标题按钮事件

React Native 错误:Animated.event now requires a second argument for options

使用 AsyncStorage 如何以及在何处保存整个 redux 存储

Realm 和 React Native - 实现自动更新的最佳实践?

React Native 使视图 Hug键盘顶部

渲染时获取未定义不是 React Native 中的对象

如何知道 FlatList 中的滚动状态?

expo 已过期卸载并再次运行以升级

horizontal水平 FlatList 前后的间距

我们可以在 react webapp 和 react native 应用程序之间共享代码吗,并且可以在 react-native 生产环境中使用

React Native:无法解析模块 fs

为什么 this.state 在react-native中未定义?

/bin/sh: adb: 找不到命令