Plug-in React Native compatibility bindings for Replicache.
https://user-images.githubusercontent.com/5165963/219898954-f5e94045-69bf-4c33-84e8-7d152c6f2c32.mov
Replicache enables us to build applications that are performant, offline-capable and collaborative. By default, it uses IndexedDB for client-side persistance. Unfortunately, this technology is not available in React Native and is only supported in web-browsers.
Thankfully, Replicache allows us to provide our own transactional data-store via kvStore
. The goal of this project is to provide some implementations of such a store, along with some guidance in getting up and running with Replicache in React Native.
React Native has relatively good support for SQLite - which provides the strict serializable transactions that we require.
In particular, we provide the choice between three SQLite bindings:
@react-native-replicache/react-native-expo-sqlite
expo-sqlite
@react-native-replicache/react-native-op-sqlite
react-native-op-sqlite
Some configuration is required to receive poke events from the server. In our example, seen here, we use a polyfill for Server Sent Events. These aren't built into React Native, but are really handy for a demo.
You most likely want to use web-sockets for this. This is relatively trivial with Pusher/Ably etc and similar to the web-app so we won't discuss that further here.
yarn add expo-crypto
yarn add @op-engineering/op-sqlite @react-native-replicache/react-native-op-sqlite
yarn add expo-sqlite @react-native-replicache/expo-sqlite
crypto.getRandomValues
on the global namespace.
kvStore
option.
createReplicacheOPSQLiteKVStore
createReplicacheExpoSQLiteKVStore
git clone https://github.com/braden1996/react-native-replicache.git
yarn install
yarn build
yarn workspace @react-native-replicache/example-mobile-react-native ios
yarn run dev
.