Skip to content

Commit

Permalink
persist async storage poc
Browse files Browse the repository at this point in the history
  • Loading branch information
solderq35 committed Mar 12, 2024
1 parent dc8f004 commit 1acf227
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
24 changes: 20 additions & 4 deletions app/_layout.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,29 @@
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import AsyncStorage from "@react-native-async-storage/async-storage";
import { createAsyncStoragePersister } from "@tanstack/query-async-storage-persister";
import { QueryClient } from "@tanstack/react-query";
import { PersistQueryClientProvider } from "@tanstack/react-query-persist-client";
import { Stack } from "expo-router";
import { AuthProvider } from "~/context/Auth";

// Create a client
const queryClient = new QueryClient();
const queryClient = new QueryClient({
defaultOptions: {
queries: {
gcTime: 1000 * 60 * 60 * 24, // 24 hours
},
},
});

const asyncStoragePersister = createAsyncStoragePersister({
storage: AsyncStorage,
});

export default function RootLayoutNav() {
return (
<QueryClientProvider client={queryClient}>
<PersistQueryClientProvider
client={queryClient}
persistOptions={{ persister: asyncStoragePersister }}
>
<AuthProvider>
<Stack
screenOptions={{
Expand All @@ -19,6 +35,6 @@ export default function RootLayoutNav() {
<Stack.Screen name="test" />
</Stack>
</AuthProvider>
</QueryClientProvider>
</PersistQueryClientProvider>
);
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
"@expo/webpack-config": "^19.0.0",
"@gorhom/bottom-sheet": "^4",
"@react-native-async-storage/async-storage": "^1.22.3",
"@tanstack/query-async-storage-persister": "^5.27.5",
"@tanstack/react-query": "^5.24.1",
"@tanstack/react-query-persist-client": "^5.27.5",
"babel-plugin-root-import": "^6.6.0",
"cross-env": "^7.0.3",
"d3-scale": "^4.0.2",
Expand Down
26 changes: 26 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2694,11 +2694,37 @@
dependencies:
"@typescript-eslint/utils" "^6.20.0"

"@tanstack/query-async-storage-persister@^5.27.5":
version "5.27.5"
resolved "https://registry.yarnpkg.com/@tanstack/query-async-storage-persister/-/query-async-storage-persister-5.27.5.tgz#a54146280076bb66bce133a9854d75a966e419c8"
integrity sha512-oCHg/vayE9r/ek8tipwqus5UOCg9xJTatzDv8pBqY+Z25P3di6phG4DD7GpMXPI4luAJmSMX/PRBmu/8nkaCCg==
dependencies:
"@tanstack/query-persist-client-core" "5.27.5"

"@tanstack/query-core@5.25.0":
version "5.25.0"
resolved "https://registry.yarnpkg.com/@tanstack/query-core/-/query-core-5.25.0.tgz#e08ed0a9fad34c8005d1a282e57280031ac50cdc"
integrity sha512-vlobHP64HTuSE68lWF1mEhwSRC5Q7gaT+a/m9S+ItuN+ruSOxe1rFnR9j0ACWQ314BPhBEVKfBQ6mHL0OWfdbQ==

"@tanstack/query-core@5.27.5":
version "5.27.5"
resolved "https://registry.yarnpkg.com/@tanstack/query-core/-/query-core-5.27.5.tgz#de4ede2094d490d0147e943212fcda51f09c0f69"
integrity sha512-HuYOo46NhzNX1SwXCmLf/Skr8B7T56cDHUN+iOhnu7+GOkUMThda64GwZpAqQzBT8TOTBQo6RQaNe0gi3Gi2fw==

"@tanstack/query-persist-client-core@5.27.5":
version "5.27.5"
resolved "https://registry.yarnpkg.com/@tanstack/query-persist-client-core/-/query-persist-client-core-5.27.5.tgz#4cb285bf8a73139bc5612db6230e4be00adbcb76"
integrity sha512-XsXZ6OioNYcc76kVP3hza4G7hgsIZBD0qMhCtyaLJNuIsLjkXCk6J5kXOHoS2MEJpGk0QdArymVmwE7auFaMog==
dependencies:
"@tanstack/query-core" "5.27.5"

"@tanstack/react-query-persist-client@^5.27.5":
version "5.27.5"
resolved "https://registry.yarnpkg.com/@tanstack/react-query-persist-client/-/react-query-persist-client-5.27.5.tgz#ae0822168db033115aa6ae97a05f56982010ca89"
integrity sha512-UFfWiJ8z2kQTS9bbEwobmg1fK96+sJ6/naWbP16SdUNMxUTzkMdgAWMsTrGGCuoOQWIwBfhOgYpIWiFIx94qkQ==
dependencies:
"@tanstack/query-persist-client-core" "5.27.5"

"@tanstack/react-query@^5.24.1":
version "5.25.0"
resolved "https://registry.yarnpkg.com/@tanstack/react-query/-/react-query-5.25.0.tgz#f4dac794cf10dd956aa56dbbdf67049a5ba2669d"
Expand Down

0 comments on commit 1acf227

Please sign in to comment.