输入值当我具有先前的值时不会更改

发布于 2025-02-13 08:40:19 字数 549 浏览 0 评论 0原文

我有一个文章字段组件,该组件加载文章对象(通过location.state),它具有空的参数(当我尝试制作新文章时)或 preexisting值当我想编辑文章时。my输入当我传递先前存在的值时,也不会更改,即使它是一个空字符串。另一个手,on Change函数仍然适用于textarea 。任何关于这种情况发生的想法,我知道我可以将输入更改为textareas,但是我想了解为什么首先发生这种情况

用于参考的沙箱

https://codesandbox.io/s/green-sopdvp ?file =/src/app.js

I have an ArticleFields component that loads an article object (through location.state) which has either empty parameters(when i try to make a new article) or preexisting values when i want to edit an article.My inputs though, won't change when i pass a preexisting value,even if it's an empty string.On the other hand ,the onChange function still works for textarea.Any ideas to why is this happening,i know i can just change the inputs to textareas,but ofcourse i want to understand why this is happening first

Here is a sandbox for reference

https://codesandbox.io/s/green-sound-sopdvp?file=/src/App.js

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怎言笑 2025-02-20 08:40:19

使用DefaultValue而不是值:

value={article.title}

Use defaultValue instead of value:

value={article.title}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文