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
+15-14Lines changed: 15 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,36 +7,34 @@ 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
31
27
To do this, copy the contents of `node_modules/@powersync/web/dist` to the root of your project (typically in the `public `directory). To make it easier to manage these files in the `public` directory, it is recommended to place the contents in a nested directory like `@powersync`.
32
28
33
-
You can run the following bash command to automate the copying process. It will create copy the contents to `/public/@powersync`.
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).
# Places assets into public/@powersync by default. Override with `--output path/from_current_working_dir`.
33
+
npx powersync-web copy-assets
34
+
# or pnpm powersync-web copy-assets
37
35
```
38
36
39
-
### 3\. Instantiate Web Workers
37
+
### 3. Instantiate Web Workers
40
38
41
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.
42
40
@@ -82,7 +80,7 @@ this.powersync = new PowerSyncDatabaseWeb({
82
80
83
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.
84
82
85
-
### 4\. Enable multiple platforms
83
+
### 4. Enable multiple platforms
86
84
87
85
To target both mobile and web platforms, you need to adjust the Metro configuration and handle platform-specific libraries accordingly.
88
86
@@ -192,6 +190,7 @@ export async function prompt(
192
190
```
193
191
194
192
Which can then be used agnostically in a component.
193
+
195
194
```js
196
195
import { Button } from'react-native';
197
196
import { prompt } from'util/prompt';
@@ -214,15 +213,17 @@ import { prompt } from 'util/prompt';
214
213
}}
215
214
/>;
216
215
```
217
-
### 5\. Configure UMD target
216
+
217
+
### 5. Configure UMD target
218
218
219
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:
220
220
221
221
1. Add `config.resolver.unstable_enablePackageExports = true;` to your `metro.config.js` file.
222
+
222
223
2. TypeScript projects: In the `tsconfig.json` file specify the `moduleResolution` to be `Bundler`.
1. From your Supabase Dashboard, select **Connect** in the top navigation bar:
6
2
7
-
* Under **Direct connection**, copy the connection string. The hostname should be `db.<PROJECT-ID>.supabase.co`, and not, for example, `aws-0-us-west-1.pooler.supabase.com`.
* Paste this URI in PowerSync instance **URI** field.
13
+
* Paste the connection string into the PowerSync instance **URI** field. PowerSync will automatically parse this URI to populate the connection details.
14
14
15
-
*Enter the **Password**for the `postgres` user in your Supabase database.
15
+
*For the **Password**field, enter your database's `postgres` user password (this is your database/project password, not your Supabase account password). Need help? Check Supabase's guide on [managing database passwords](https://supabase.com/docs/guides/database/managing-passwords).
16
16
17
-
* Supabase also [refers to this password](https://supabase.com/docs/guides/database/managing-passwords) as the *database password* or *project password*.
17
+
* Note: PowerSync includes Supabase's CA certificate by default, so you can use `verify-full` SSL mode without additional configuration.
18
+
19
+
Your connection settings should look similar to this:
0 commit comments