MiNiMAL
MiNiMAL2y ago

Best practices for implementing an offline application

Hey there! I'm building a full stack react-native app with Expo and a tRPC backend. I'd like for this app to be functional offline. Currently I'm accomplishing this via a simple optimistic update like:
const createUser = trpc.userCreate.useMutation({
onMutate: async () => {
// Cancel users fetch
await utils.users.cancel()
// Get current users list
const previousData = utils.users.getData() || []
// Append new user
utils.users.setData([...previousData, { id: uuid.v1(), name } as User])
return { previousData }
},
})
const createUser = trpc.userCreate.useMutation({
onMutate: async () => {
// Cancel users fetch
await utils.users.cancel()
// Get current users list
const previousData = utils.users.getData() || []
// Append new user
utils.users.setData([...previousData, { id: uuid.v1(), name } as User])
return { previousData }
},
})
This is working pretty well (it's late and I plan on extensively testing this tomorrow). I'd like to confirm what best practices, if any, have been established by the community before continuing.
1 Reply
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View