通过传递其ID在React中获取数据属性

发布于 2025-02-08 16:32:23 字数 336 浏览 0 评论 0原文

我是新来的React,并且有一个我不知道如何解决的问题 - 加载页面后,我将相当大的数据存储在Redux工具包中 - 一系列对象。每个对象都有自己的ID。

接下来,经过一定的用户操作,我要获得对象ID,我需要从中获取数据 - 我认为每个用户单击,映射整个数组并找到正确的ID IS NES'最有效的方法。是否可以创建一些可以通过传递其ID而不映射整个数组的ID来为我提供有关对象的信息?类似的事情 -

getDataFromId(id) - and it would return object's data.

处理此类问题的最有效方法是什么?

i'm new into React and I have a problem that I don't know how to solve - after loading page I'm storing pretty big data in Redux toolkit - an array of objects. Each object has its own id.

Next, after some user action, i'm getting the object ID and I need to get data from it - I think that every user click, mapping the whole array and find the item with correct ID isn't the most effective way. Is it possible to create something that would give me the info about the object stored in Redux by passing it's ID without mapping whole array? Something like -

getDataFromId(id) - and it would return object's data.

What is the most effective way to deal with problems like that?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文