You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: client-sdk-references/react-native-and-expo/react-native-web-support.mdx
+13-13Lines changed: 13 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,24 +7,20 @@ title: "React Native Web Support"
7
7
Support for React Native Web is available since versions 1.12.1 of the [PowerSync React Native SDK](/client-sdk-references/react-native-and-expo) and 1.8.0 if the [JavaScript/Web SDK](/client-sdk-references/javascript-web), and is currently in a **beta** release.
8
8
9
9
A demo app showcasing this functionality is available here:
## Configuring PowerSync in your React Native for Web project
18
14
19
15
To ensure that PowerSync features are fully supported in your React Native Web project, follow the below steps. This documentation covers necessary web worker configurations, database instantiation, and multi-platform implementations.
20
16
21
-
### 1\. Install Web SDK
17
+
### 1. Install Web SDK
22
18
23
19
The [PowerSync Web SDK](/client-sdk-references/javascript-web), alongside the [PowerSync React Native SDK](/client-sdk-references/react-native-and-expo), is required for Web support.
24
20
25
21
See installation instructions [here](https://www.npmjs.com/package/@powersync/web).
26
22
27
-
### 2\. Configure Web Workers
23
+
### 2. Configure Web Workers
28
24
29
25
For React Native for Web, workers need to be configured when instantiating `PowerSyncDatabase`. An example of this is available [here](https://github.com/powersync-ja/powersync-js/blob/main/demos/react-native-web-supabase-todolist/library/powersync/system.ts).
30
26
@@ -33,11 +29,12 @@ To do this, copy the contents of `node_modules/@powersync/web/dist` to the root
33
29
The [`@powersync/web`](https://github.com/powersync-ja/powersync-js/tree/main/packages/web) package includes a CLI utility which can copy the required assets to the `public` directory (configurable with the `--output` option).
34
30
35
31
```bash
36
-
npx powersync-web copy-assets # Places assets into public/@powersync by default. Override with `--output path/from_current_working_dir`.
32
+
# Places assets into public/@powersync by default. Override with `--output path/from_current_working_dir`.
33
+
npx powersync-web copy-assets
37
34
# or pnpm powersync-web copy-assets
38
35
```
39
36
40
-
### 3\. Instantiate Web Workers
37
+
### 3. Instantiate Web Workers
41
38
42
39
The example below demonstrates how to instantiate the workers (PowerSync requires a database and a sync worker) when instantiating `PowerSyncDatabase`. You can either specify a path to the worker (they are available in the `worker` directory of the `dist` contents), or provide a factory function to create the worker.
43
40
@@ -83,7 +80,7 @@ this.powersync = new PowerSyncDatabaseWeb({
83
80
84
81
This `PowerSyncDatabaseWeb` database will be used alongside the native `PowerSyncDatabase` to support platform-specific implementations. See the [Instantiating PowerSync](/client-sdk-references/react-native-and-expo/react-native-web-support#implementations) section below for more details.
85
82
86
-
### 4\. Enable multiple platforms
83
+
### 4. Enable multiple platforms
87
84
88
85
To target both mobile and web platforms, you need to adjust the Metro configuration and handle platform-specific libraries accordingly.
89
86
@@ -193,6 +190,7 @@ export async function prompt(
193
190
```
194
191
195
192
Which can then be used agnostically in a component.
193
+
196
194
```js
197
195
import { Button } from'react-native';
198
196
import { prompt } from'util/prompt';
@@ -215,15 +213,17 @@ import { prompt } from 'util/prompt';
215
213
}}
216
214
/>;
217
215
```
218
-
### 5\. Configure UMD target
216
+
217
+
### 5. Configure UMD target
219
218
220
219
React Native Web requires the UMD target of `@powersync/web` (available at `@powersync/web/umd`). To fully support this target version, configure the following in your project:
221
220
222
221
1. Add `config.resolver.unstable_enablePackageExports = true;` to your `metro.config.js` file.
222
+
223
223
2. TypeScript projects: In the `tsconfig.json` file specify the `moduleResolution` to be `Bundler`.
0 commit comments