reactjs - React JS 道具没有更新
问题描述
在下面的代码中,当我更改 pendingCount 的状态时,第一个 key prop 发生了变化,但< Pending/>中的那个没有。这是为什么?
<div>
<motion.p
key={pendingCount}
whileHover={{textDecoration:"underline"}}
style={{cursor:"pointer"}}
onClick={ ()=>{ render(<Pending key={pendingCount} data={AllPendingsData}/>) } }
className="position-relative d-inline-block pe-3"
>
Pending Requests
<span className="badge rounded-pill bg-dark ms-2">
{pendingCount}
</span>
</motion.p>
</div>
我还想补充一件事,那就是我想做的是在< Pending/>的 props 更改时重新渲染它。更改密钥道具是我在互联网上找到的建议方法之一,但它对我不起作用。那么对于功能组件有没有更好或首选的方法呢?
解决方案
你使用道具还是状态?
为了测试你尝试使用状态
推荐阅读
- c# - C# HttpWebRequest 返回错误 403。如何从 C# 中的 HttpWebRequest 修复 403 错误
- python - 使用 numpy savetxt 时丢失精度
- arduino - Arduino中的独立闪烁灯
- python - 在与 Hangman 的输入匹配后,如何将每个元素或字母显示为破折号?
- strapi - Strapi + MongoDB 不保存密码字段
- c# - 远程验证asp.net核心telerik网格弹出
- html - 我如何对齐这些?
- pivot - 如何在 Qliksense 的数据透视表的列中为每个部分生成总计?
- javascript - 我的功能不等待其他功能
- javascript - 发布与前端的智能合约接口