Menu

An offline write queue for React Native, and the two reader questions that changed it
📰

An offline write queue for React Native, and the two reader questions that changed it

DEV Community: reactnative·Praveen Singh·about 21 hours ago
#pKXyN8FQ
#devtoreactnative#devto#dev#write#server
Reading 0:00
15s threshold

Short answer: Bareship queues offline writes with TanStack Query: a paused mutation is saved to MMKV, so it survives the app being killed, and replays in order when the phone reconnects. Every write gets an Idempotency-Key when the user taps, reused for every attempt, so the server applies it once. Since 0.4.0, each write also records the account that made it and is never sent for anyone else, and a write can cancel the dependent writes queued behind it if the server rejects it.

In the launch post I said Bareship saves a like made offline, keeps it through a

restart and sends it once when the phone reconnects, and promised the next post would show how.

Two readers on dev.to then asked questions I hadn't fully answered. Dave Kurian

asked whose write it is when someone else signs in before it's sent. Odd Eggs Studio

asked what happens to the writes behind one the server rejects. Both answers are now code, released in

0.4.0 .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.