功能性反应本机组件不起作用

问题描述 投票:0回答:4
console.log永远不会触发,我不知道为什么...我尝试将组件写为 功能游戏... 我尝试了此操作,而没有触摸可接触性,并且仅在返回函数中放上按钮...实际上没有任何功能,也没有任何模拟器

SMALL更新:
我将返回函数的内容更改为:

<TouchableOpacity activeOpacity={0.5} onPress={()=>console.log("HELLO")}> <Text title={props.game.id} key={props.game.id} color={props.color} style={styles.buttons}>{props.game.id}</Text> </TouchableOpacity>

组件呈现没有错误或任何内容的组件,它可以被标签,并且不透明度更改,但未调用OnPress(因此没有控制台日志)

这似乎不仅限于功能组件...
i我在我的房屋屏幕上添加了反应文档1:1的按钮示例,而OnPress事件永远不会被调用:

<Button onPress={() => { alert('You tapped the button!'); }} title="Press Me" />

请尝试此代码。
import React from 'react';
import { Text, Button, Image, TouchableOpacity } from 'react-native';
import { useHistory } from "react-router-native";
import { getFileUrl } from '../db/firebaseDb';
import styles from '../modules/Styles';

const GameIcon = (props) => {
  const history = useHistory();

  const handleClick = (pId) => {
    console.log("TEST");
    history.push("/game");
  }

  return (
    <TouchableOpacity activeOpacity={0.5} onPress={handleClick}>
    <Text title={props.game.id} key={props.game.id} color={props.color} style={styles.buttons}>{props.game.id}</Text>
    </TouchableOpacity>
  )
}

export default GameIcon;
reactjs react-native react-functional-component onpress
4个回答
2
投票

所以我进行了一些MacOS更新,事实证明他们以某种方式
    是原因...我仍然不明白...
    应该独立于操作系统更新,对吗? 
    无论如何... 15分钟,然后重新开始,现在都开始了
    功能尽可能地发挥作用 - 再次感谢
    帮助!

0
投票
update:今天再次启动我的Mac和同样的问题 - 它正在工作 更新后的整天昨天,但今天完全相同 - 所有按钮都响应被按下,没有按钮触发onpress 函数
Final更新: 我找到了这样做的原因:这是一个反应的错误,仅在调试模式下发生 - 在此处阅读更多:

https://github.com/facebook/react-native/issues/28687

可能也可能是反应的手机处理者

npm install --save react-native-gesture-handler

然后在index.js

0
投票
import 'react-native-gesture-handler';

以这种方式尝试使用相同的PBM,并且当我添加括号时它是修复的

enter code here return ( <TouchableOpacity activeOpacity={0.5} onPress={() => handleClick() }> <Text title={props.game.id} key={props.game.id} color={props.color} style={styles.buttons}>{props.game.id}</Text> </TouchableOpacity> )
    

0
投票
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.