@electric-sql/react 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +46 -0
- package/package.json +70 -0
package/README.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# React integration for ElectricSQL
|
|
2
|
+
|
|
3
|
+
Electric is Postgres sync for modern apps.
|
|
4
|
+
|
|
5
|
+
Electric provides an HTTP interface to Postgres to enable massive number of clients to query and get real-time updates to data in "shapes" i.e. subsets of the database. Electric turns Postgres into a real-time database.
|
|
6
|
+
|
|
7
|
+
This packages exposes a `useShape` hook for pulling shape data into your React components.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
`npm i @electricsql/react`
|
|
12
|
+
|
|
13
|
+
## How to use
|
|
14
|
+
|
|
15
|
+
Add the Shapes provider
|
|
16
|
+
```tsx
|
|
17
|
+
import { ShapesProvider } from "@electric-sql/react"
|
|
18
|
+
|
|
19
|
+
ReactDOM.createRoot(document.getElementById(`root`)!).render(
|
|
20
|
+
<ShapesProvider>
|
|
21
|
+
<App />
|
|
22
|
+
</ShapesProvider>
|
|
23
|
+
)
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Add `useShape` to a component
|
|
27
|
+
```
|
|
28
|
+
import { useShape } from "@electric-sql/react"
|
|
29
|
+
|
|
30
|
+
export default function MyComponent () {
|
|
31
|
+
const { isUpToDate, data as fooData } = useShape({
|
|
32
|
+
shape: { table: `foo` },
|
|
33
|
+
baseUrl: "http://my-api.com/",
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
if (!isUpToDate) {
|
|
37
|
+
return <div>loading</div>
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<div>
|
|
42
|
+
{data.map(foo => <div>{foo.title}</div>)}
|
|
43
|
+
</div>
|
|
44
|
+
)
|
|
45
|
+
}
|
|
46
|
+
```
|
package/package.json
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@electric-sql/react",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "React hooks for ElectricSQL",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/electric-sql/electric-next.git"
|
|
13
|
+
},
|
|
14
|
+
"author": "",
|
|
15
|
+
"license": "ISC",
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/electric-sql/electric-next/issues"
|
|
18
|
+
},
|
|
19
|
+
"homepage": "https://github.com/electric-sql/electric-next#readme",
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@electric-sql/next": "0.0.1"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@testing-library/react": "^16.0.0",
|
|
25
|
+
"@types/pg": "^8.11.6",
|
|
26
|
+
"@types/react": "^18.3.3",
|
|
27
|
+
"@types/uuid": "^10.0.0",
|
|
28
|
+
"@typescript-eslint/eslint-plugin": "^7.14.1",
|
|
29
|
+
"@typescript-eslint/parser": "^7.14.1",
|
|
30
|
+
"concurrently": "^8.2.2",
|
|
31
|
+
"eslint": "^8.57.0",
|
|
32
|
+
"eslint-config-prettier": "^9.1.0",
|
|
33
|
+
"eslint-plugin-prettier": "^5.1.3",
|
|
34
|
+
"glob": "^10.3.10",
|
|
35
|
+
"global-jsdom": "24.0.0",
|
|
36
|
+
"pg": "^8.12.0",
|
|
37
|
+
"prettier": "^3.3.2",
|
|
38
|
+
"react": "^18.3.1",
|
|
39
|
+
"shx": "^0.3.4",
|
|
40
|
+
"tsup": "^8.0.1",
|
|
41
|
+
"typescript": "^5.5.2",
|
|
42
|
+
"uuid": "^10.0.0",
|
|
43
|
+
"vitest": "^2.0.2"
|
|
44
|
+
},
|
|
45
|
+
"peerDependencies": {
|
|
46
|
+
"react": "^18.3.1"
|
|
47
|
+
},
|
|
48
|
+
"peerDependenciesMeta": {
|
|
49
|
+
"react": {
|
|
50
|
+
"optional": true
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
"exports": {
|
|
54
|
+
".": "./dist/index.js"
|
|
55
|
+
},
|
|
56
|
+
"typesVersions": {
|
|
57
|
+
"*": {
|
|
58
|
+
"*": [
|
|
59
|
+
"./dist/index.d.ts"
|
|
60
|
+
]
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
"scripts": {
|
|
64
|
+
"test": "npx vitest",
|
|
65
|
+
"typecheck": "tsc -p tsconfig.json",
|
|
66
|
+
"build": "shx rm -rf dist && concurrently \"tsup\" \"tsc -p tsconfig.build.json\"",
|
|
67
|
+
"stylecheck": "eslint . --quiet",
|
|
68
|
+
"format": "eslint . --fix"
|
|
69
|
+
}
|
|
70
|
+
}
|