-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
React Native GUN
Gun works out of the box with React Native.
Use the minified version of Gun that is bundled with the standard distribution:
import Gun from 'gun/gun.min.js';
// Connect to a remote server
const gun = new Gun("https://your-gun-server.com/gun");
// use Gun as usual
In the browser, Gun will dump the graph into LocalStorage to achieve longer-term storage. On a Node server, it can dump into a JSON file or into another storage system via an adapter.
In React Native, if you want to retain application data for either offline use or for long-term storage on the device itself, you can plug Gun into a few community built adapters:
If you choose not to use any long-term storage option, that's totally fine. Gun will keep as much of the graph as possible in memory, which will be dumped every time the application is restarted.
Let's say you've got a Gun server running on a Node process on your machine; while you're developing your React Native application, you want to connect up to that server rather than some remote, production server over the internet. Instead of giving "localhost", provide the Local-Area-Network (LAN) IP address for your machine:
const gun = new Gun("http://192.168.0.01:gun");