Skip to content

Commit 682417f

Browse files
committed
docs: select
1 parent b17aa9e commit 682417f

File tree

6 files changed

+99
-9
lines changed

6 files changed

+99
-9
lines changed

docs/pages/documentation/data/use-delete.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@
22

33
Performs a DELETE on the table.
44

5-
```js highlight=4,5,6,7,8,9,10,11,12,13,14
5+
```js highlight=4,5,6,7,8,9,10,11,12,13,14,15,16
66
import { useDelete } from 'react-supabase'
77

88
function Page() {
99
const [
10-
{ count, data, error, fetching }, deleteTodos] = useDelete(
10+
{ count, data, error, fetching },
11+
deleteTodos,
12+
] = useDelete(
1113
'todos',
14+
// Passing optional options
1215
{
13-
// Passing optional options
1416
options: {
1517
returning: 'represenation',
1618
count: 'exact',
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,33 @@
11
# useInsert
2+
3+
Performs an INSERT into the table.
4+
5+
```js highlight=4,5,6,7,8,9,10,11,12,13
6+
import { useInsert } from 'react-supabase'
7+
8+
function Page() {
9+
const [{ count, data, error, fetching }, insertTodo] = useInsert(
10+
'todos',
11+
// Passing optional options
12+
{
13+
options: {
14+
returning: 'represenation',
15+
count: 'exact',
16+
},
17+
},
18+
)
19+
20+
async function onClickDelete(id) {
21+
const { count, data, error } = await deleteTodos(
22+
(query) => query.eq('id', id),
23+
{
24+
// Override options from hook init
25+
returning: 'minimal',
26+
count: 'estimated',
27+
},
28+
)
29+
}
30+
31+
return ...
32+
}
33+
```
Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,55 @@
1-
import Callout from 'nextra-theme-docs/callout'
1+
import Link from 'next/link'
22

33
# useSelect
44

5-
<Callout>
6-
When using a dynamic `filter`, you must ...
7-
</Callout>
5+
Performs vertical filtering with SELECT.
6+
7+
```js highlight=4,5,6,7,8,9,10,11,12,13,14,15,16,17,18
8+
import { useSelect } from 'react-supabase'
9+
10+
function Page() {
11+
const [
12+
{ count, data, error, fetching },
13+
selectTodos,
14+
] = useSelect(
15+
'todos',
16+
// Passing optional options
17+
{
18+
columns: 'id, name, description',
19+
filter: (query) => query.eq('status', 'completed'),
20+
options: {
21+
count: 'exact',
22+
head: false,
23+
},
24+
},
25+
)
26+
27+
if (error) return <div>{error.message}</div>
28+
if (fetching) return <div>Loading todos</div>
29+
if (data?.length === 0) return <div>No todos</div>
30+
31+
return ...
32+
}
33+
```
34+
35+
## Dynamic filtering
36+
37+
When using dynamic filters, you must make sure filters aren't recreated every render. Otherwise, your request can get stuck in an infinite loop.
38+
39+
The easiest way to avoid this is to create dynamic filters with the [`useFilter`](/documentation/data/use-filter) hook:
40+
41+
```js
42+
import { useState } from 'react'
43+
import { useFilter, useSelect } from 'react-supabase'
44+
45+
function Page() {
46+
const [status, setStatus] = useState('completed')
47+
const filter = useFilter(
48+
(query) => query.eq('status', status),
49+
[status],
50+
)
51+
const [{ data }] = useSelect('todos', { filter })
52+
53+
return ...
54+
}
55+
```
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# useTable
2+
3+
Realtime table
4+
5+
```js
6+
import { useSelect, useSubscription } from 'react-supabase'
7+
```
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"user-context": "UserContext"
2+
"user-context": "UserContext",
3+
"live-table": "useTable"
34
}

src/hooks/data/use-select.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ export type UseSelectResponse<Data = any> = [
1717
]
1818

1919
export type UseSelectOptions = {
20-
head?: boolean
2120
count?: null | Count
21+
head?: boolean
2222
}
2323

2424
export type UseSelectConfig<Data = any> = {

0 commit comments

Comments
 (0)