Skip to content
Source
Sign inSign up
samwillis/neon-realtime-electric
Open History to see the last commit

index.tsx

11 lines433 Bytes

1import { useEffect, useState } from 'react'
2import { Shape, ShapeStream } from '@electric-sql/client'
3import { options, type Item } from '../shared'
4​
5const stream = new ShapeStream<Item>(options)
6const shape = new Shape(stream)
7export function Basic() {
8 const [rows, setRows] = useState<Item[]>([])
9 useEffect(() => shape.subscribe(({ rows }) => setRows(rows)), [])
10 return <pre data-testid="rows">{JSON.stringify(rows)}</pre>