gpt4 book ai didi

reactjs - Material-ui TextField 与 React-Redux 混淆

转载 作者:行者123 更新时间:2023-12-03 14:28:49 25 4
gpt4 key购买 nike

我有一个带有 TextField 的 React 组件:

<TextField
hintText="name"
floatingLabelText="Your name:"/>

该组件通过使用react-redux的connect函数生成的容器连接到存储。目前没有参数传递给容器。并且不会在组件中的任何位置分派(dispatch)任何操作。

当我尝试在 TextField 中输入一些文本时,我看到正在调度一些操作,从 redux-devtools 我可以看到:

enter image description here

对于我输入的每个字符,始终会调度相同的 SET_FOCUS_PAGE 操作,并将页面属性设置为 TextFieldchange 事件。另外,在控制台上我有很多这样的警告:

Warning: This synthetic event is reused for performance reasons. If you're seeing this, you're accessing the property `bubbles` on a released/nullified synthetic event. This is set to null. If you must keep the original synthetic event around, use event.persist(). See react-event-pooling for more information.

我无法理解这一切,为什么 SET_FOCUS_PAGE 是由无权访问该操作的组件调度的? change 事件如何在页面属性中结束?那里发生了什么!?

最佳答案

看起来您正在将合成事件传递到 redux 状态树。您更有可能想要而不是事件本身。

例如:

<TextField
hintText="name"
floatingLabelText="Your name:"
onChange={(event) => handleChangeText(event)}
/>

调用:

const handleChangeText = (event) => {
console.log('the text is:', event.target.value);
}

如果你用它更新你的状态树,那么你应该得到你需要的东西。我编写 console.log 的地方就是您触发捕获输入的操作的地方。

关于reactjs - Material-ui TextField 与 React-Redux 混淆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38955476/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com