Skip to main content

usePowerSync()

function usePowerSync(): AbstractPowerSyncDatabase

Custom hook that provides access to the PowerSync context.

Returns

AbstractPowerSyncDatabase

The PowerSync Database instance.

Example

const Component = () => {
const db = usePowerSync();
const [lists, setLists] = React.useState([]);

React.useEffect(() => {
powersync.getAll('SELECT * from lists').then(setLists)
}, []);

return <ul>
{lists.map(list => <li key={list.id}>{list.name}</li>)}
</ul>
};