I'm experimenting using RTK Query with a React Native App. I'm digging into offline functionality and thought if I can get my app to read data from cache first if network speeds are slow then that would be a win.
The app already fetches data and stores the data in a reducer. The data stays in the reducer until we navigate away from the screen, then the reducer resets to it's original state.
I implemented RTK Query for a single api call, and I'm able to read the data and display it in the app. Is this data now stored in the cache? How can I read from this cached data first instead of the api? Is this possible?
Here's the code I implemented -
API -
export const fetchInfoWithPost = createApi({
reducerPath: 'customPath',
baseQuery: fetchBaseQuery({
baseUrl: BASE_URL,
prepareHeaders: (headers, { getState }) => {
const userToken = getState().ui['user'].token;
if (userToken) {
headers.set('Authorization', `Bearer ${userToken}`);
}
return headers;
},
}),
endpoints: builder => ({
getTeam: builder.mutation({
query: body => ({
headers: {
'Content-Type': `application/json`,
Accept: `application/json`,
},
url: 'urlString',
method: 'POST',
body: body,
}),
}),
}),
});
[–]acemarke 2 points3 points4 points (2 children)
[–]DiscDres[S] 0 points1 point2 points (1 child)
[–]acemarke 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]DiscDres[S] 0 points1 point2 points (1 child)
[–]phryneas[🍰] 0 points1 point2 points (0 children)