The code from docs:
https://www.apollographql.com/docs/react/essentials/local-state#cache-initialization
import { ApolloClient } from 'apollo-client';
import { InMemoryCache } from 'apollo-cache-inmemory';
const cache = new InMemoryCache();
const client = new ApolloClient({
cache,
resolvers: { /* ... */ },
});
const data = {
todos: [],
visibilityFilter: 'SHOW_ALL',
networkStatus: {
__typename: 'NetworkStatus',
isConnected: false,
},
};
cache.writeData({ data });
client.onResetStore(() => cache.writeData({ data }));
This line causes error in typescript:
client.onResetStore(() => cache.writeData({ data }))
TypeScript error: Type 'void' is not assignable to type 'Promise<any>'. TS2322
Try client.onResetStore(async () => cache.writeData({ data }));
Try
client.onResetStore(async () => cache.writeData({ data }));
I was having this issue, and adding async solved it for me.
Sounds like this was resolved - closing, thanks!
Most helpful comment
Try
client.onResetStore(async () => cache.writeData({ data }));