Apollo-client: useMutation update,the cache changed,but UI not change

Created on 3 Oct 2019  ·  4Comments  ·  Source: apollographql/apollo-client

I useMutation to send message ,but the message list in chat window not change. I found that the cache has changed . Please help , I can't understand.

image

and the cache has changed
image

The useQuery not work . UI have no change :(

But~! When I put them in one js file. it works.... why???

All 4 comments

From the docs,

Important: You should call these methods on your app's ApolloClient object, not directly on the cache. By doing so, the ApolloClient object broadcasts cache changes to your entire app, which enables automatic UI updates. If you call these methods directly on the cache instead, changes are not broadcast.

In any case, this seems like a question and should probably go to Stackoverflow.

文档中

重要提示:您应该在应用程序的ApolloClient对象上而不是直接在缓存上调用这些方法。这样,ApolloClient对象会将缓存更改广播到整个应用程序,从而启用自动UI更新。如果直接在缓存上调用这些方法,则不会广播更改。

无论如何,这似乎是一个问题,可能应该转到Stackoverflow。

I tried use apollo client , but result is the same , message list not change.. cache changed .

bug

What makes me wonder is why the components don't work.It works just fine in one file? (Machine translated :)

lastmesassg

The problem most likely is the state mutation:

chat.messages.push(addMessage)

Should rather use concat or [...chat, addMessage]

Was this page helpful?
0 / 5 - 0 ratings