Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: improve readability of the type signature of useSWRSubscription #460

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions pages/docs/subscription.en-US.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ import { Callout } from 'nextra-theme-docs'
`useSWRSubscription` is a React hook that allows subscribing to real-time data sources with SWR.

```tsx
useSWRSubscription<Data, Error>(key: Key, subscribe: (key: Key, options: { next: (error?: Error | null, data: Data) => void }) => () => void): { data?: Data, error?: Error }
useSWRSubscription<Data, Error>(
key: Key,
subscribe: (
key: Key,
options: { next: (error?: Error | null, data: Data) => void }
) => () => void
): { data?: Data, error?: Error }
```

### API
Expand Down Expand Up @@ -56,7 +62,7 @@ import useSWRSubscription from 'swr/subscription'
function Post({ id }) {
const { data } = useSWRSubscription(['views', id], ([_, postId], { next }) => {
const ref = firebase.database().ref('views/' + postId)
ref.on('value',
ref.on('value',
snapshot => next(null, snapshot.data()),
err => next(err)
)
Expand All @@ -79,7 +85,7 @@ function App() {
socket.addEventListener('error', (event) => next(event.error))
return () => socket.close()
})

if (error) return <div>failed to load</div>
if (!data) return <div>loading...</div>
return <div>hello {data}!</div>
Expand All @@ -88,9 +94,9 @@ function App() {

### Deduplication

`useSWRSubscription` deduplicates the subscription requests with the same key.
If there are multiple components using the same key, they will share the same subscription.
`useSWRSubscription` deduplicates the subscription requests with the same key.
If there are multiple components using the same key, they will share the same subscription.
When the last component using the key unmounts, the subscription will be closed.

This means that if you have multiple components using the same key, they will all receive the same data.
This means that if you have multiple components using the same key, they will all receive the same data.
And there's only one subscription to the real-time data source per key.
18 changes: 12 additions & 6 deletions pages/docs/subscription.es-ES.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ import { Callout } from 'nextra-theme-docs'
`useSWRSubscription` is a React hook that allows subscribing to real-time data sources with SWR.

```tsx
useSWRSubscription<Data, Error>(key: Key, subscribe: (key: Key, options: { next: (error?: Error | null, data: Data) => void }) => () => void): { data?: Data, error?: Error }
useSWRSubscription<Data, Error>(
key: Key,
subscribe: (
key: Key,
options: { next: (error?: Error | null, data: Data) => void }
) => () => void
): { data?: Data, error?: Error }
```

### API
Expand Down Expand Up @@ -56,7 +62,7 @@ import useSWRSubscription from 'swr/subscription'
function Post({ id }) {
const { data } = useSWRSubscription(['views', id], ([_, postId], { next }) => {
const ref = firebase.database().ref('views/' + postId)
ref.on('value',
ref.on('value',
snapshot => next(null, snapshot.data()),
err => next(err)
)
Expand All @@ -79,7 +85,7 @@ function App() {
socket.addEventListener('error', (event) => next(event.error))
return () => socket.close()
})

if (error) return <div>failed to load</div>
if (!data) return <div>loading...</div>
return <div>hello {data}!</div>
Expand All @@ -88,9 +94,9 @@ function App() {

### Deduplication

`useSWRSubscription` deduplicates the subscription requests with the same key.
If there are multiple components using the same key, they will share the same subscription.
`useSWRSubscription` deduplicates the subscription requests with the same key.
If there are multiple components using the same key, they will share the same subscription.
When the last component using the key unmounts, the subscription will be closed.

This means that if you have multiple components using the same key, they will all receive the same data.
This means that if you have multiple components using the same key, they will all receive the same data.
And there's only one subscription to the real-time data source per key.
8 changes: 7 additions & 1 deletion pages/docs/subscription.ja.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ import { Callout } from 'nextra-theme-docs'
`useSWRSubscription` はリアルタイムのデータソースを SWR で購読するための React フックです。

```tsx
useSWRSubscription<Data, Error>(key: Key, subscribe: (key: Key, options: { next: (error?: Error | null, data: Data) => void }) => () => void): { data?: Data, error?: Error }
useSWRSubscription<Data, Error>(
key: Key,
subscribe: (
key: Key,
options: { next: (error?: Error | null, data: Data) => void }
) => () => void
): { data?: Data, error?: Error }
```

### API
Expand Down
8 changes: 7 additions & 1 deletion pages/docs/subscription.ko.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ import { Callout } from 'nextra-theme-docs'
`useSWRSubscription`은 SWR을 사용하여 실시간 데이터를 구독할 수 있는 훅입니다.

```tsx
useSWRSubscription<Data, Error>(key: Key, subscribe: (key: Key, options: { next: (error?: Error | null, data: Data) => void }) => () => void): { data?: Data, error?: Error }
useSWRSubscription<Data, Error>(
key: Key,
subscribe: (
key: Key,
options: { next: (error?: Error | null, data: Data) => void }
) => () => void
): { data?: Data, error?: Error }
```

### API
Expand Down
12 changes: 9 additions & 3 deletions pages/docs/subscription.pt-BR.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ import { Callout } from 'nextra-theme-docs'
`useSWRSubscription` é um hook React que permite se inscrever em fontes de dados em tempo real com o SWR.

```tsx
useSWRSubscription<Data, Error>(key: Key, subscribe: (key: Key, options: { next: (error?: Error | null, data: Data) => void }) => () => void): { data?: Data, error?: Error }
useSWRSubscription<Data, Error>(
key: Key,
subscribe: (
key: Key,
options: { next: (error?: Error | null, data: Data) => void }
) => () => void
): { data?: Data, error?: Error }
```

### API
Expand Down Expand Up @@ -55,7 +61,7 @@ import useSWRSubscription from 'swr/subscription'
function Post({ id }) {
const { data } = useSWRSubscription(['views', id], ([_, postId], { next }) => {
const ref = firebase.database().ref('views/' + postId)
ref.on('value',
ref.on('value',
snapshot => next(null, snapshot.data()),
err => next(err)
)
Expand Down Expand Up @@ -91,4 +97,4 @@ function App() {
Quando o último componente usando a chave for desmontado, a inscrição será fechada.

Isso significa que se você tiver vários componentes usando a mesma chave, todos eles irão receber os mesmos dados.
E há apenas uma única inscrição para a fonte de dados em tempo real por chave.
E há apenas uma única inscrição para a fonte de dados em tempo real por chave.
8 changes: 7 additions & 1 deletion pages/docs/subscription.ru.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ import { Callout } from 'nextra-theme-docs'
`useSWRSubscription` это хук React, который позволяет подписываться на реальные источники данных в реальном времени с помощью SWR.

```tsx
useSWRSubscription<Data, Error>(key: Key, subscribe: (key: Key, options: { next: (error?: Error | null, data: Data) => void }) => () => void): { data?: Data, error?: Error }
useSWRSubscription<Data, Error>(
key: Key,
subscribe: (
key: Key,
options: { next: (error?: Error | null, data: Data) => void }
) => () => void
): { data?: Data, error?: Error }
```

### API
Expand Down
18 changes: 12 additions & 6 deletions pages/docs/subscription.zh-CN.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ import { Callout } from 'nextra-theme-docs'
`useSWRSubscription` is a React hook that allows subscribing to real-time data sources with SWR.

```tsx
useSWRSubscription<Data, Error>(key: Key, subscribe: (key: Key, options: { next: (error?: Error | null, data: Data) => void }) => () => void): { data?: Data, error?: Error }
useSWRSubscription<Data, Error>(
key: Key,
subscribe: (
key: Key,
options: { next: (error?: Error | null, data: Data) => void }
) => () => void
): { data?: Data, error?: Error }
```

### API
Expand Down Expand Up @@ -56,7 +62,7 @@ import useSWRSubscription from 'swr/subscription'
function Post({ id }) {
const { data } = useSWRSubscription(['views', id], ([_, postId], { next }) => {
const ref = firebase.database().ref('views/' + postId)
ref.on('value',
ref.on('value',
snapshot => next(null, snapshot.data()),
err => next(err)
)
Expand All @@ -79,7 +85,7 @@ function App() {
socket.addEventListener('error', (event) => next(event.error))
return () => socket.close()
})

if (error) return <div>failed to load</div>
if (!data) return <div>loading...</div>
return <div>hello {data}!</div>
Expand All @@ -88,9 +94,9 @@ function App() {

### Deduplication

`useSWRSubscription` deduplicates the subscription requests with the same key.
If there are multiple components using the same key, they will share the same subscription.
`useSWRSubscription` deduplicates the subscription requests with the same key.
If there are multiple components using the same key, they will share the same subscription.
When the last component using the key unmounts, the subscription will be closed.

This means that if you have multiple components using the same key, they will all receive the same data.
This means that if you have multiple components using the same key, they will all receive the same data.
And there's only one subscription to the real-time data source per key.