使用React Quill的Usestate和Onchange无法正常工作,不确定如何修复
我有一系列文本输入字段 - 它们的输入由这样的usestate管理:
const [formFields, setFormFields] = useState([
{ textinput1: "", textinput2: "", textinput3: "", reactQuill: "" } ]);
他们的句柄更改是通过此功能管理的,因为可以添加更多的文本字段,并且添加的每个索引都必须保存其输入:
function handleChangeInput(index, event) {
const values = [...formFields];
values[index][event.target.name] = event.target.value
setFormFields(values);
}
并且这就是他们的外观和功能,如预期的:
{
formFields.map((formField, index) => (
<React.Fragement key={index}>
<TextField
name='textinput1'
value={formField.textinput1}
onChange={event => handleChangeInput(index, event)}
/>
))
}
但是,当我尝试使用React Quill(Rich Text Editor)输入的相同的确切逻辑时,它根本无法正常工作。因此,例如,这是行不通的:
<ReactQuill
name="reactQuill"
onChange={event => handleChangeInput(index, event)}
value={formField.reactQuill}
/>
我会遇到“名称”的错误,而我不确定如何解决这个问题?预先感谢您是否知道如何解决此问题!
I have a series of text input fields - their input is managed by useState like this:
const [formFields, setFormFields] = useState([
{ textinput1: "", textinput2: "", textinput3: "", reactQuill: "" } ]);
Their handle change is managed with this function, because more text fields can be added, and every index of the additions has to have its input get saved:
function handleChangeInput(index, event) {
const values = [...formFields];
values[index][event.target.name] = event.target.value
setFormFields(values);
}
And this is what they look like and function as intended:
{
formFields.map((formField, index) => (
<React.Fragement key={index}>
<TextField
name='textinput1'
value={formField.textinput1}
onChange={event => handleChangeInput(index, event)}
/>
))
}
However, when I try the same exact logic with the React Quill (rich text editor) input, it's not working at all. So for example, this will not work:
<ReactQuill
name="reactQuill"
onChange={event => handleChangeInput(index, event)}
value={formField.reactQuill}
/>
I am getting an error of "name" being undefined, and I am not sure how to work around this? Thanks in advance if anyone knows how to fix this!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是固定的。由于React Quill Text Editor不会像其他文本字段那样返回传统事件,因此必须将我的HandleChangeInput修改为:
并且必须更改文本字段的OnChange::
React for React Quill必须更改为:
我希望将来对某人有所帮助!
The issue was fixed. Since the React Quill text editor does not return a traditional event like other text fields do, my handleChangeInput had to be modified to:
And the onChange for text fields had to be changed to:
The onChange for React Quill had to be changed to:
I hope this helps someone in the future!