You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have apolloclient for storybook configured with InMemoryCache to have the same behavior in storybook as in my app.
Switching component stories keeps the old state of the cache alive, so I have to refresh the browser to purge it.
If I call client.clearStore() inside my stories, I can purge the cache.
I tried to create a decorator that does a client.clearStore() on ApolloClient. But I can not get it chained to be inside the ApolloProvider. Seems like the Apollo context gets added inside the decorators. So I ended up adding the decorator as a wrapper inside every ComponentStory.
How could I achieve some global way to purge the cache when switching to another story?
my cache purging component:
export default function ApolloCacheClearDecorator({children}: {children: JSX.Element}) {
const [cleared, setCleared] = useState(false);
const client = useApolloClient();
useEffect(() => {
if (cleared) return;
client.clearStore();
setCleared(true);
}, [cleared, client]);
if (!cleared) return <div>Clearing Apollo cache...</div>;
return children;
}
I have apolloclient for storybook configured with InMemoryCache to have the same behavior in storybook as in my app.
Switching component stories keeps the old state of the cache alive, so I have to refresh the browser to purge it.
If I call
client.clearStore()
inside my stories, I can purge the cache.I tried to create a decorator that does a
client.clearStore()
on ApolloClient. But I can not get it chained to be inside the ApolloProvider. Seems like the Apollo context gets added inside the decorators. So I ended up adding the decorator as a wrapper inside every ComponentStory.How could I achieve some global way to purge the cache when switching to another story?
my cache purging component:
my apollo config in .storybook/preview.js
The text was updated successfully, but these errors were encountered: