taro
taro copied to clipboard
taro4.0创建的0.73版本react-native的view的onClick事件异常
相关平台
React Native
复现仓库
https://github.com/a709691139/taro4.0.git
使用框架: React
复现步骤
随便写个onClick useState, 然后点击几次view,就发现onClick事件一直是旧的
import { useState } from 'react';
import { View } from '@tarojs/components';
const Index = () => {
const [staticed, setStaticed] = useState(false);
return (
<View>
formStaticed: {JSON.stringify(staticed)}
<View
onClick={() => {
console.log('old value ', staticed);
setStaticed(!staticed);
}}>
切换
</View>
</View>
);
};
export default Index;
期望结果
console.log('old value ', staticed); 这里的输出永远是false
实际结果
应该是true或false轮着来
环境信息
👽 Taro v4.0.0-beta.8
Taro CLI 4.0.0-beta.8 environment info:
System:
OS: Windows 11 10.0.22621
Binaries:
Node: 18.16.0 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.19 - C:\Program Files\nodejs\yarn.CMD
npm: 9.5.1 - C:\Program Files\nodejs\npm.CMD
npmPackages:
@tarojs/cli: 4.0.0-beta.8 => 4.0.0-beta.8
@tarojs/components: 4.0.0-beta.8 => 4.0.0-beta.8
@tarojs/components-rn: 4.0.0-beta.8 => 4.0.0-beta.8
@tarojs/helper: 4.0.0-beta.8 => 4.0.0-beta.8
@tarojs/plugin-framework-react: 4.0.0-beta.8 => 4.0.0-beta.8
@tarojs/plugin-platform-alipay: 4.0.0-beta.8 => 4.0.0-beta.8
@tarojs/plugin-platform-h5: 4.0.0-beta.8 => 4.0.0-beta.8
@tarojs/plugin-platform-jd: 4.0.0-beta.8 => 4.0.0-beta.8
@tarojs/plugin-platform-qq: 4.0.0-beta.8 => 4.0.0-beta.8
@tarojs/plugin-platform-swan: 4.0.0-beta.8 => 4.0.0-beta.8
@tarojs/plugin-platform-tt: 4.0.0-beta.8 => 4.0.0-beta.8
@tarojs/plugin-platform-weapp: 4.0.0-beta.8 => 4.0.0-beta.8
@tarojs/react: 4.0.0-beta.8 => 4.0.0-beta.8
@tarojs/rn-runner: 4.0.0-beta.8 => 4.0.0-beta.8
@tarojs/rn-supporter: 4.0.0-beta.8 => 4.0.0-beta.8
@tarojs/runtime: 4.0.0-beta.8 => 4.0.0-beta.8
@tarojs/runtime-rn: 4.0.0-beta.8 => 4.0.0-beta.8
@tarojs/shared: 4.0.0-beta.8 => 4.0.0-beta.8
@tarojs/taro: 4.0.0-beta.8 => 4.0.0-beta.8
@tarojs/taro-loader: 4.0.0-beta.8 => 4.0.0-beta.8
@tarojs/taro-rn: 4.0.0-beta.8 => 4.0.0-beta.8
@tarojs/webpack5-runner: 4.0.0-beta.8 => 4.0.0-beta.8
babel-preset-taro: 4.0.0-beta.8 => 4.0.0-beta.8
eslint-config-taro: 4.0.0-beta.8 => 4.0.0-beta.8
expo: ~50.0.2 => 50.0.4
react: ^18.2.0 => 18.2.0
react-native: ^0.73.1 => 0.73.3
这里是运行结果
找到解决方法了,因为PanResponder拿到的值都是旧的, props要改用ref来获取
https://github.com/NervJS/taro/pull/15212 关联pull request