Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

function component 对input组件的变化有问题 #9242

Open
conan51551 opened this issue Apr 30, 2021 · 3 comments
Open

function component 对input组件的变化有问题 #9242

conan51551 opened this issue Apr 30, 2021 · 3 comments
Labels
F-react Framework - React question Further information is requested T-weapp Target - 编译到微信小程序 V-3 Version - 3.x

Comments

@conan51551
Copy link

相关平台

微信小程序

复现仓库

https://github.com/conan51551/taro-demo
小程序基础库: 2.16.1
使用框架: React

复现步骤

1.在使用了hook的function component中,使用组件InputNumber组件
2.InputNumber中使用了Taro的Input组件,在onBlur的时候,如果输入大于5的数字,会调用父组件change充值Input的value为5
3.只有第一次成功重置了,之后虽然每次都setNum了,但是页面并没有刷新

const [Num, setNum] = useState(1);

  const change = (_num) => {
    setNum(() => _num);
  };

  return (
    <View>
      <InputNumber num={Num} change={change} />
    </View>
  );

期望结果

当输入大于5的数字,数字每次都被改成5

实际结果

在class componet中可以,但是在hook的function component中,只有第一次被修改成了5

环境信息

Taro CLI 3.2.5 environment info:
    System:
      OS: macOS 11.2.3
      Shell: 5.8 - /bin/zsh
    Binaries:
      Node: 14.15.5 - ~/.nvm/versions/node/v14.15.5/bin/node
      Yarn: 1.22.4 - /usr/local/bin/yarn
      npm: 6.14.11 - ~/.nvm/versions/node/v14.15.5/bin/npm
    npmPackages:
      @tarojs/components: 3.1.1 => 3.1.1
      @tarojs/mini-runner: 3.1.1 => 3.1.1
      @tarojs/react: 3.1.1 => 3.1.1
      @tarojs/runtime: 3.1.1 => 3.1.1
      @tarojs/taro: 3.1.1 => 3.1.1
      @tarojs/webpack-runner: 3.1.1 => 3.1.1
      babel-preset-taro: 3.1.1 => 3.1.1
      eslint-config-taro: 3.1.1 => 3.1.1
      react: ^17.0.0 => 17.0.2
@taro-bot2 taro-bot2 bot added F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x labels Apr 30, 2021
@Chen-jj
Copy link
Contributor

Chen-jj commented May 7, 2021

@conan51551 Demo 链接挂了

@Chen-jj Chen-jj added the question Further information is requested label May 7, 2021
@conan51551
Copy link
Author

@conan51551 Demo 链接挂了

现在好了

@yangqianqq
Copy link

我也遇见了 还有input输入的值重置时绑定了state设置对应的state也不能更新到最新的state 求解决!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-react Framework - React question Further information is requested T-weapp Target - 编译到微信小程序 V-3 Version - 3.x
Projects
None yet
Development

No branches or pull requests

3 participants