输入重新渲染和每次我使用formik时输入的焦点
在Formik中使用FieldArray时,我的输入始终会恢复,因此当用户类型时,它们会失去焦点。
<FieldArray
name="wallets"
className="space-y-4"
component={(arrayHelpers) => (
<>
{
formik.values.wallets.map((wallet, i) => (
<div
key={i}
{...}
遵循文档后,Formik使用索引作为儿童键
,这不是一个好练习,但是我在钱包中没有任何其他不变的价值(所有这些价值形式)。我相信,重新渲染并不是将索引用作密钥的问题,而是只需在每个值变化时将整个映射值重新呈现。
有什么方法可以防止这种情况发生而不会成为巨大的黑客?
When using FieldArray in Formik my inputs are always rerendered and thus they lose focus when a user types.
<FieldArray
name="wallets"
className="space-y-4"
component={(arrayHelpers) => (
<>
{
formik.values.wallets.map((wallet, i) => (
<div
key={i}
{...}
Following the docs, Formik uses an index as the child key
, which is not a good practice, but I don't have any other immutable value in the wallet to use (all of them might be changed within form). I believe the re-render is not a matter of using the index as a key but simply Formik re-rendering the whole mapped values each time a value changes.
Is there any way to prevent this to happen without being a huge hack?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
更改时,您只需要放置一个应为同一组件的键,
当道具像这样
解决方案:
删除
并执行此操作
You just have to put a key that should be permanent for the same component when props change
like this
Solution :
remove
and do this