Skip to content

Commit 1fbdbe7

Browse files
committed
chore: update readme
1 parent 5ac63e6 commit 1fbdbe7

File tree

3 files changed

+90
-15
lines changed

3 files changed

+90
-15
lines changed

.github/ISSUE_TEMPLATE/config.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
blank_issues_enabled: false
22
contact_links:
3-
- name: Ask Question
4-
url: https://github.com/tmm/react-supabase/discussions
5-
about: Ask questions and discuss with other community members
3+
- name: Ask Question
4+
url: https://github.com/tmm/react-supabase/discussions
5+
about: Ask questions and discuss with other community members

README.md

Lines changed: 79 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
`react-supabase` is a React Hooks library for [Supabase](https://supabase.io).
44

5+
With `react-supabase`, components can request and access data declaratively without needing to handle state updates on their own.
6+
57
<br/>
68

79
## Installation
810

9-
Inside your React project directory, install:
10-
1111
```
1212
yarn add react-supabase @supabase/supabase-js
1313
# or
@@ -33,7 +33,7 @@ const App = () => (
3333
)
3434
```
3535

36-
Now every component and element inside and under the `Provider` can use the Supabase client:
36+
Now every component inside and under the `Provider` can use the Supabase client:
3737

3838
```js
3939
import { useSelect } from 'react-supabase'
@@ -57,6 +57,82 @@ const Todos = () => {
5757

5858
<br/>
5959

60+
### API
61+
62+
#### Auth
63+
64+
```js
65+
useAuthStateChange((event, session) => {
66+
console.log(`Supbase auth event: ${event}`, session)
67+
})
68+
```
69+
70+
```js
71+
const [{ error, fetching }, resetPassword] = useResetPassword({
72+
options: {
73+
redirectTo: 'https://example.com/welcome',
74+
},
75+
})
76+
77+
const { error } = await resetPassword('user@example.com', {
78+
redirectTo: 'https://example.com/reset',
79+
})
80+
```
81+
82+
```js
83+
const [{ error, fetching, user, session }, signIn] = useSignIn({
84+
// provider: 'github',
85+
options: {
86+
redirectTo: 'https://example.com/dashboard',
87+
// scopes: 'repo gist notifications',
88+
},
89+
})
90+
91+
const { error, session, user } = await signIn(
92+
{
93+
email: 'user@example.com',
94+
password: 'foobarbaz', // omit for magic link
95+
// provider: 'github',
96+
},
97+
{
98+
redirectTo: 'https://example.com/dashboard',
99+
// scopes: 'repo gist notifications',
100+
},
101+
)
102+
```
103+
104+
```js
105+
const [{ error, fetching }, signOut] = useSignOut()
106+
107+
const { error } = await signOut()
108+
```
109+
110+
```js
111+
const [{ error, fetching, user, session }, signUp] = useSignUp({
112+
options: {
113+
redirectTo: 'https://example.com/dashboard',
114+
},
115+
})
116+
117+
const { error, session, user } = await signUp(
118+
{
119+
email: 'user@example.com',
120+
password: 'foobarbaz',
121+
},
122+
{
123+
redirectTo: 'https://example.com/dashboard',
124+
},
125+
)
126+
```
127+
128+
#### Data
129+
130+
#### Realtime
131+
132+
#### Storage
133+
134+
<br/>
135+
60136
## License
61137

62138
The MIT License.

src/hooks/data/use-select.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
1+
import { useCallback, useEffect, useRef, useState } from 'react'
22

33
import { Count, Filter, PostgrestError } from '../../types'
44
import { useClient } from '../use-client'
@@ -35,19 +35,18 @@ export function useSelect<Data = any>(
3535
const isMounted = useRef(false)
3636
const [state, setState] = useState<UseSelectState>(initialState)
3737

38-
const source = useMemo(() => {
39-
const { columns, filter, options } = config
40-
const source = client.from<Data>(table).select(columns, options)
41-
return filter ? filter(source) : source
42-
}, [client, config, table])
43-
4438
const execute = useCallback(async () => {
4539
setState({ ...initialState, fetching: true })
46-
const { count, data, error } = await source
40+
const source = client
41+
.from<Data>(table)
42+
.select(config.columns, config.options)
43+
const { count, data, error } = await (config.filter
44+
? config.filter(source)
45+
: source)
4746
const res = { count, data, error }
4847
if (isMounted.current) setState({ ...res, fetching: false })
4948
return res
50-
}, [source])
49+
}, [client, config, table])
5150

5251
/* eslint-disable react-hooks/exhaustive-deps */
5352
useEffect(() => {

0 commit comments

Comments
 (0)