Replies: 1 comment
-
The same question seems to be valid for the createPowerSyncPersister that offers a react hook. import React, { useEffect, useState } from 'react';
import { usePowerSync } from '@powersync/react';
import { createPowerSyncPersister } from 'tinybase/persisters/persister-powersync';
import { Persister, Store, createStore } from 'tinybase';
import { Provider as TinybaseProvider, useCreatePersister, useCreateStore } from 'tinybase/ui-react';
export function AppStoreProvider({ children }: { children: React.ReactNode }) {
const store = useCreateStore(() => createStore().setTablesSchema({...}));
const ps = usePowerSync();
useCreatePersister(
store,
(store) => {
// ----> `ps` is `null` on first function call and initializes an invalid persister
return createPowerSyncPersister(store, ps, 'my-key');
},
[ps],
async (persister: TinybasePersister) => {
await persister.startAutoLoad();
await persister.startAutoSave();
},
);
return (
<TinybaseProvider
storesById={{ ... }}
relationshipsById={{ ... }}
>
{children}
</TinybaseProvider>
);
} I get the following error:
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I would like to test the persister-cr-sqlite-wasm in a React application, but I'm struggling with the setup due to the async initialization of the sqlite database.
First, I installed the
@vlcn.io/crsqlite-wasm
package, something that could be added to the tinybase documentation.Then I tried to adapt the example from the documentation page and ended up with something like this:
The problem is that
sqliteDb
isnull
on the first run and will create an invalid persister which fails in thestartAutoLoad()
below.How can I make this example working? What is missing to initialize the SQLite DB correctly?
Beta Was this translation helpful? Give feedback.
All reactions