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

Input受控模式,手动修改value后,onChange会自动触发,并传入上一个value的值 #1876

Closed
WweiweiSmile opened this issue Jan 18, 2024 · 2 comments · Fixed by #1912
Assignees

Comments

@WweiweiSmile
Copy link

NutUI React 包名

@nutui/nutui-react

NutUI React 版本号

2.3.6

平台

weapp

重现链接

https://y83cjj-5173.csb.app/

重现步骤

安卓端微信小程序调用以下组件可复现,注:微信开发者工具与CodeSandbox无法复现

import { View } from "@tarojs/components";
import { Input, Button } from "@nutui/nutui-react-taro";
import { useState } from "react";

const Test = () => {
  const [keyword, setKeyword] = useState("");

  return <View>
    <Input value={keyword} onChange={setKeyword}/>
    <Button onClick={() => {setKeyword("");}}>清空</Button>
  </View>;
};

export default Test
;

期望的结果是什么?

<Input />组件输入"test"值后,点击清空按钮,输入框清空

实际的结果是什么?

点击清空按钮后keyword更新为"",随后<Input />组件的onChange事件会被自动调用并传入"test"值,导致<Input />组件的值未能清空

环境信息

No response

其他补充信息

No response

@WweiweiSmile
Copy link
Author

@cdx111
Copy link

cdx111 commented Jan 19, 2024

i am the same problem as well

@eiinu eiinu added upstream 上游依赖的问题,比如 Taro、小程序或者其他第三方依赖 and removed upstream 上游依赖的问题,比如 Taro、小程序或者其他第三方依赖 labels Jan 26, 2024
@oasis-cloud oasis-cloud self-assigned this Jan 29, 2024
@oasis-cloud oasis-cloud linked a pull request Jan 29, 2024 that will close this issue
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants