Skip to content

Commit 9c7d047

Browse files
committed
docs: options
1 parent 682417f commit 9c7d047

File tree

21 files changed

+308
-149
lines changed

21 files changed

+308
-149
lines changed

docs/pages/documentation/auth/use-auth-state-change.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ function Page() {
1414
}
1515
```
1616

17-
Note: Auth listener automatically cleaned up during [cleanup phase](https://reactjs.org/docs/hooks-effect.html#effects-with-cleanup).
17+
Note: Auth listener is automatically cleaned up during the hook’s [cleanup phase](https://reactjs.org/docs/hooks-effect.html#effects-with-cleanup).

docs/pages/documentation/auth/use-reset-password.md

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,14 @@
22

33
Sends reset request to email address.
44

5-
```js highlight=4,5,6,7,8,9
5+
```js highlight=4
66
import { useResetPassword } from 'react-supabase'
77

88
function Page() {
9-
const [{ error, fetching }, resetPassword] = useResetPassword({
10-
// Passing optional options
11-
options: {
12-
redirectTo: 'https://example.com/welcome',
13-
},
14-
})
9+
const [{ error, fetching }, resetPassword] = useResetPassword()
1510

1611
async function onClickResetPassword() {
17-
const { error } = await resetPassword('user@example.com', {
18-
// Override options from hook init
19-
redirectTo: 'https://example.com/reset',
20-
})
12+
const { error } = await resetPassword('user@example.com')
2113
}
2214

2315
if (error) return <div>Error sending email</div>
@@ -26,3 +18,23 @@ function Page() {
2618
return ...
2719
}
2820
```
21+
22+
## Passing options
23+
24+
During hook initialization:
25+
26+
```js
27+
const [{ error, fetching }, resetPassword] = useResetPassword({
28+
options: {
29+
redirectTo: 'https://example.com/welcome',
30+
},
31+
})
32+
```
33+
34+
Or execute function:
35+
36+
```js
37+
const { error } = await resetPassword('user@example.com', {
38+
redirectTo: 'https://example.com/reset',
39+
})
40+
```

docs/pages/documentation/auth/use-signin.md

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,17 @@
22

33
Log in existing user, or login via a third-party provider.
44

5-
```js highlight=4,5,6,7,8,9
5+
```js highlight=4
66
import { useSignIn } from 'react-supabase'
77

88
function Page() {
9-
const [{ error, fetching, session, user }, signIn] = useSignIn({
10-
// Passing optional options
11-
options: {
12-
redirectTo: 'https://example.com/dashboard',
13-
},
14-
})
9+
const [{ error, fetching, session, user }, signIn] = useSignIn()
1510

1611
async function onClickSignIn() {
17-
const { error, session, user } = await signIn(
18-
{
19-
email: 'user@example.com',
20-
password: 'foobarbaz',
21-
},
22-
{
23-
// Override options from hook init
24-
redirectTo: 'https://example.com/account',
25-
},
26-
)
12+
const { error, session, user } = await signIn({
13+
email: 'user@example.com',
14+
password: 'foobarbaz',
15+
})
2716
}
2817

2918
if (error) return <div>Error signing in</div>
@@ -34,6 +23,32 @@ function Page() {
3423
}
3524
```
3625

26+
## Passing options
27+
28+
During hook initialization:
29+
30+
```js
31+
const [{ error, fetching, session, user }, signIn] = useSignIn({
32+
options: {
33+
redirectTo: 'https://example.com/dashboard',
34+
},
35+
})
36+
```
37+
38+
Or the execute function:
39+
40+
```js
41+
const { error, session, user } = await signIn(
42+
{
43+
email: 'user@example.com',
44+
password: 'foobarbaz',
45+
},
46+
{
47+
redirectTo: 'https://example.com/account',
48+
},
49+
)
50+
```
51+
3752
## Magic links
3853

3954
Omit password from the execute function:
@@ -55,7 +70,7 @@ const [{ error, fetching, user, session }, signIn] = useSignIn({
5570
})
5671
```
5772

58-
Or the execute function:
73+
Or execute function:
5974

6075
```js
6176
const { error, session, user } = await signIn(

docs/pages/documentation/auth/use-signup.md

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,17 @@
22

33
Creates new user.
44

5-
```js highlight=4,5,6,7,8,9
5+
```js highlight=4
66
import { useSignUp } from 'react-supabase'
77

88
function Page() {
9-
const [{ error, fetching, session, user }, signUp] = useSignUp({
10-
// Passing optional options
11-
options: {
12-
redirectTo: 'https://example.com/dashboard',
13-
},
14-
})
9+
const [{ error, fetching, session, user }, signUp] = useSignUp()
1510

1611
async function onClickSignUp() {
17-
const { error, session, user } = await signUp(
18-
{
19-
email: 'user@example.com',
20-
password: 'foobarbaz',
21-
},
22-
{
23-
// Override options from hook init
24-
redirectTo: 'https://example.com/welcome',
25-
},
26-
)
12+
const { error, session, user } = await signUp({
13+
email: 'user@example.com',
14+
password: 'foobarbaz',
15+
})
2716
}
2817

2918
if (error) return <div>Error signing up</div>
@@ -33,3 +22,29 @@ function Page() {
3322
return ...
3423
}
3524
```
25+
26+
## Passing options
27+
28+
During hook initialization:
29+
30+
```js
31+
const [{ error, fetching, session, user }, signUp] = useSignUp({
32+
options: {
33+
redirectTo: 'https://example.com/dashboard',
34+
},
35+
})
36+
```
37+
38+
Or execute function:
39+
40+
```js
41+
const { error, session, user } = await signUp(
42+
{
43+
email: 'user@example.com',
44+
password: 'foobarbaz',
45+
},
46+
{
47+
redirectTo: 'https://example.com/welcome',
48+
},
49+
)
50+
```
Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,47 @@
11
# useDelete
22

3-
Performs a DELETE on the table.
3+
Performs DELETE on table.
44

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

88
function Page() {
9-
const [
10-
{ count, data, error, fetching },
11-
deleteTodos,
12-
] = useDelete(
13-
'todos',
14-
// Passing optional options
15-
{
16-
options: {
17-
returning: 'represenation',
18-
count: 'exact',
19-
},
20-
},
21-
)
9+
const [{ count, data, error, fetching }, deleteTodos] = useDelete('todos')
2210

2311
async function onClickDelete(id) {
2412
const { count, data, error } = await deleteTodos(
2513
(query) => query.eq('id', id),
26-
{
27-
// Override options from hook init
28-
returning: 'minimal',
29-
count: 'estimated',
30-
},
3114
)
3215
}
3316

3417
return ...
3518
}
3619
```
3720

38-
Throws error during execute if `filter` is not passed during hook initialization or execute method directly.
21+
Throws error during execute if a filter is not passed during hook initialization or execute method.
22+
23+
## Passing options
24+
25+
During hook initialization:
26+
27+
```js
28+
const [{ count, data, error, fetching }, deleteTodos] = useDelete('todos', {
29+
filter: (query) => query.eq('status', 'completed'),
30+
options: {
31+
returning: 'represenation',
32+
count: 'exact',
33+
},
34+
})
35+
```
36+
37+
Or execute function:
38+
39+
```js
40+
const { count, data, error } = await deleteTodos(
41+
(query) => query.eq('id', id),
42+
{
43+
returning: 'minimal',
44+
count: 'estimated',
45+
},
46+
)
47+
```
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,24 @@
11
# useFilter
2+
3+
Creates dynamic filter for using with other hooks.
4+
5+
```js highlight=4,5,6,7,8,9,10,11
6+
import { useFilter, useSelect } from 'react-supabase'
7+
8+
function Page() {
9+
const filter = useFilter(
10+
(query) =>
11+
query
12+
.eq('status', status)
13+
.textSearch('name', `'exercise' & 'shopping'`)
14+
.limit(10),
15+
[status],
16+
)
17+
// Pass filter to other hooks
18+
const [{ data }] = useSelect('todos', { filter })
19+
20+
return ...
21+
}
22+
```
23+
24+
For an example, see [`useSelect` "Dynamic Filtering"](/documentation/data/use-select#dynamic-filtering).
Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,44 @@
11
# useInsert
22

3-
Performs an INSERT into the table.
3+
Performs INSERT into table.
44

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

88
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-
)
9+
const [{ count, data, error, fetching }, insertTodos] = useInsert('todos')
10+
11+
async function onClickInsert(name) {
12+
const { count, data, error } = await insertTodos({
13+
name,
14+
})
2915
}
3016

3117
return ...
3218
}
3319
```
20+
21+
## Passing options
22+
23+
During hook initialization:
24+
25+
```js
26+
const [{ count, data, error, fetching }, insertTodos] = useInsert('todos', {
27+
options: {
28+
returning: 'represenation',
29+
count: 'exact',
30+
},
31+
})
32+
```
33+
34+
Or execute function:
35+
36+
```js
37+
const { count, data, error } = await insertTodos(
38+
{ name: 'Buy more cheese' },
39+
{
40+
count: 'estimated',
41+
returning: 'minimal',
42+
},
43+
)
44+
```

0 commit comments

Comments
 (0)