Skip to content

Testing React Query + Container Pattern #646

Answered by ghost
ghost asked this question in General
Discussion options

You must be logged in to vote

Figured it out! Hope this helps someone else out:

const someFunction = (devices: DeviceInterface[], premiumEnabled: boolean): ReactElement => {
    const queryCache = makeQueryCache();

    queryCache.setQueryData(['sites'], [{ id: mySite, name: 'MySite' }, { id: otherSite, name: 'OtherSite' }, { id: noSiteId, name: 'NoSite' }]);
    queryCache.setQueryData(['devices'], devices);

    return (
        <ReactQueryCacheProvider queryCache={queryCache}>
            <DeviceList premiumEnabled={premiumEnabled} />
        </ReactQueryCacheProvider>
    );
};

So, what you want to do is create a cache that the container/component can use in lieu of reaching out to the API. So, if you useQuery fin…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
0 participants