[英]Keep multiple loading states after calling graphql mutation many times
I'm using react and react apollo in my application and have a question.我在我的应用程序中使用 react 和 react apollo 并且有一个问题。 I have a page that contains list of users.我有一个包含用户列表的页面。 Every item contains "+" button.每个项目都包含“+”按钮。 When I click on item I want to display spinner until the mutation will finished.当我单击项目时,我想显示微调器,直到突变完成。
Could you suggest me better solution for keeping loading
for each mutation call?你能建议我更好的解决方案来保持每个突变调用的loading
吗? Now I just store it into array, but I think it can be solved better现在我只是将它存储到数组中,但我认为它可以更好地解决
You need to store the relation between one loading
process and the corresponding user
item.您需要存储一个loading
过程和相应的user
项之间的关系。
I suggest (without knowing your requirements) to have a loadings
array, where you add a loading item
containing the user id
onClick, and remove the loading item
when done.我建议(不知道您的要求)有一个loadings
数组,在其中添加一个包含user id
onClick 的加载loading item
,并在完成后删除loading item
。 A loading item
may also contain other info if necessary.如果需要, loading item
还可以包含其他信息。
You also probably need to store the relation between the (probably asynchronous) process
and the loading item
(or the user item
), so you know which loading item
has finished.您可能还需要存储(可能是异步的) process
与loading item
(或user item
)之间的关系,以便您知道哪个loading item
已完成。
You might do that by你可以这样做
process id
from the process
when you invoke it, and store that id inside the loading item
together with the user item id
,当您调用它时从process
接收process id
,并将该 id 与user item id
一起存储在loading item
中,loading id
as a closure when you invoke the process
, and remove the corresponding loading item
, eg inside a .then((xyz)=>{... removeLoading(processId)...})
.或者您可以在调用process
时将loading id
作为闭包存储,并删除相应的loading item
,例如在.then((xyz)=>{... removeLoading(processId)...})
中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.