Skip to content

Commit 6395217

Browse files
update readme (#36)
1 parent c665b3f commit 6395217

File tree

1 file changed

+5
-97
lines changed

1 file changed

+5
-97
lines changed

packages/powersync-sdk-react-native/README.md

Lines changed: 5 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -79,109 +79,17 @@ Add the Babel plugin to your `babel.config.js` file
7979
};
8080
```
8181

82-
## Native Projects
82+
# Native Projects
8383

8484
This package uses native libraries. Create native Android and iOS projects (if not created already) with
8585

8686
```bash
8787
npx expo run:android
88+
# OR
89+
npx expo run:ios
8890
```
8991

90-
# Getting Started
92+
# Learn More
93+
Refer to our [full documentation](https://docs.powersync.com/client-sdk-references/react-native-and-expo) to learn more.
9194

92-
See our [Docs](https://docs.powersync.co/usage/installation/client-side-setup/integrating-with-your-backend#react-native-and-expo) for detailed instructions.
9395

94-
```JavaScript
95-
import {
96-
Column,
97-
ColumnType,
98-
RNQSPowerSyncDatabaseOpenFactory,
99-
Schema,
100-
Table
101-
} from '@journeyapps/powersync-sdk-react-native';
102-
103-
export const AppSchema = new Schema([
104-
new Table({ name: 'customers', columns: [new Column({ name: 'name', type: ColumnType.TEXT })] })
105-
]);
106-
107-
let PowerSync;
108-
109-
export const openDatabase = async () => {
110-
const PowerSync = new RNQSPowerSyncDatabaseOpenFactory({
111-
schema: AppSchema,
112-
dbFilename: 'test.sqlite'
113-
//location: 'optional location directory to DB file'
114-
}).getInstance();
115-
116-
await PowerSync.init();
117-
118-
// Run local statements.
119-
await PowerSync.execute('INSERT INTO customers(id, name) VALUES(uuid(), ?)', ['Fred']);
120-
};
121-
122-
class Connector {
123-
async fetchCredentials() {
124-
// TODO logic to fetch a session
125-
return {
126-
endpoint: '[The PowerSync instance URL]',
127-
token: 'An authentication token',
128-
expiresAt: 'When the token expires',
129-
userID: 'User ID to associate the session with'
130-
};
131-
}
132-
133-
async uploadData(database) {
134-
// Upload local changes to backend, see docs for example
135-
}
136-
}
137-
138-
export const connectPowerSync = async () => {
139-
const connector = new Connector(); // Which was declared above
140-
await PowerSync.connect(connector);
141-
};
142-
143-
// Use queries in React Components
144-
export const CustomerListDisplay = () => {
145-
const customers = usePowerSyncWatchedQuery('SELECT * from customers');
146-
147-
return (
148-
<View>
149-
{customers.map((l) => (
150-
<Text key={l.id}>{JSON.stringify(l)}</Text>
151-
))}
152-
</View>
153-
);
154-
};
155-
156-
```
157-
158-
Refer to our [full documentation](https://docs.powersync.co/client-sdk-references/react-native-and-expo) to learn more.
159-
160-
# Known Issues
161-
162-
## Android
163-
The PowerSync connection relies heavily on HTTP streams. React Native does not support streams out of the box, so we use the [polyfills](#polyfills-fetch) mentioned. There is currently an open [issue](https://github.com/facebook/flipper/issues/2495) where the Flipper network plugin does not allow Stream events to fire. This plugin needs to be [disabled](https://stackoverflow.com/questions/69235694/react-native-cant-connect-to-sse-in-android/69235695#69235695) in order for HTTP streams to work.
164-
165-
Uncomment the following from
166-
`android/app/src/debug/java/com/<projectname>/ReactNativeFlipper.java`
167-
```java
168-
// NetworkFlipperPlugin networkFlipperPlugin = new NetworkFlipperPlugin();
169-
// NetworkingModule.setCustomClientBuilder(
170-
// new NetworkingModule.CustomClientBuilder() {
171-
// @Override
172-
// public void apply(OkHttpClient.Builder builder) {
173-
// builder.addNetworkInterceptor(new FlipperOkhttpInterceptor(networkFlipperPlugin));
174-
// }
175-
// });
176-
// client.addPlugin(networkFlipperPlugin);
177-
```
178-
179-
Disable the dev client network inspector
180-
`android/gradle.properties`
181-
```
182-
# Enable network inspector
183-
EX_DEV_CLIENT_NETWORK_INSPECTOR=false
184-
```
185-
186-
## iOS
187-
Testing offline mode on an iOS simulator by disabling the host machine's entire internet connection will cause the device to remain offline even after the internet connection has been restored. This issue seems to affect all network requests in an application.

0 commit comments

Comments
 (0)