1.1.3 • Published 24 days ago

@journeyapps/powersync-react v1.1.3

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
24 days ago

React components for PowerSync

Context

Configure a PowerSync DB connection and add it to a context provider.

// App.jsx
import { PowerSyncDatabase } from '@journeyapps/powersync-react-native';
import { PowerSyncContext } from "@journeyapps/powersync-react";
export const App = () => {
    const powerSync = React.useMemo(() => {
        // Setup PowerSync client
    }, [])

    return <PowerSyncContext.Provider value={powerSync}>
        {/** Insert your components here */ }
    </PowerSyncContext.Provider>
}

Accessing PowerSync

The provided PowerSync client is available with the usePowerSync hook.

// TodoListDisplay.jsx
import { usePowerSync } from "@journeyapps/powersync-react";

export const TodoListDisplay = () => {
    const powersync = 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>
    }

Watched Queries

Watched queries will automatically update when a dependant table is updated.

// TodoListDisplay.jsx
import { usePowerSyncWatchedQuery } from "@journeyapps/powersync-react";

export const TodoListDisplay = () => {
    const todoLists = usePowerSyncWatchedQuery('SELECT * from lists');

    return <View>
      {todoLists.map((l) => (
        <Text key={l.id}>{JSON.stringify(l)}</Text>
      ))}
    </View>
}
1.1.3

24 days ago

1.1.2

26 days ago

1.1.1

1 month ago

1.1.0

1 month ago

1.0.8

2 months ago

1.0.7

2 months ago

1.0.6

2 months ago

1.0.5

3 months ago

1.0.4

3 months ago

1.0.3

3 months ago

1.0.2

4 months ago

1.0.1

4 months ago

1.0.0

5 months ago

0.1.3

6 months ago

0.1.2

6 months ago

0.1.1

6 months ago

0.1.0

6 months ago

0.0.2

6 months ago

0.0.1

7 months ago

0.0.0-dev.5abb174b

7 months ago

0.0.0-dev.0c850373

7 months ago

0.0.1-alpha.0

7 months ago

0.0.0-dev.d73d7629

7 months ago

0.0.0-dev.58d5fbd6

7 months ago

0.0.0-dev.e785bdb4

7 months ago

0.0.0-dev.35216a5d

7 months ago

0.0.0-dev.c55100aa

7 months ago

0.0.0-dev.88285f4e

7 months ago