Skip to content

Commit

Permalink
Merge pull request #347 from HeinrichvonStein/rn-connection
Browse files Browse the repository at this point in the history
fix: reconnect powersync toggle for rn-chat demo
  • Loading branch information
kobiebotha authored Oct 17, 2024
2 parents 38ac694 + 0999b04 commit edaf0e3
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import '@azure/core-asynciterator-polyfill';
import { PowerSyncContext, PowerSyncDatabase } from '@powersync/react-native';
import Logger from 'js-logger';
import { ReactNode, useMemo } from 'react';
import { ReactNode, useEffect, useMemo } from 'react';

import { useAuth } from './AuthProvider';
import { Connector } from '../lib/connector';
Expand All @@ -20,9 +20,11 @@ export const PowerSyncProvider = ({ children }: { children: ReactNode }) => {
database: { dbFilename: 'test.sqlite' }
//location: 'optional location directory to DB file'
});

powerSync.init();
return powerSync;
}, []);

useEffect(() => {
if (isSyncEnabled) {
powerSync
.connect(connector)
Expand All @@ -34,9 +36,7 @@ export const PowerSyncProvider = ({ children }: { children: ReactNode }) => {
.then(() => console.log('not connected'))
.catch(console.error);
}

return powerSync;
}, [isSyncEnabled]);
}, [isSyncEnabled, powerSync]);

return <PowerSyncContext.Provider value={powerSync}>{children}</PowerSyncContext.Provider>;
};

0 comments on commit edaf0e3

Please sign in to comment.