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(suspensive.org): add docs for @suspensive/jotai #1084

Merged
merged 27 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
a24770e
docs(suspensive.org): add mata data for jotai docs
gwansikk Jul 14, 2024
4428cfa
docs(suspensive.org): add jotai installation section
gwansikk Jul 14, 2024
ce92537
docs(suspensive.org): add jotai Atom section
gwansikk Jul 14, 2024
11257c9
docs(suspensive.org): add jotai AtomValue section
gwansikk Jul 14, 2024
d246cea
docs(suspensive.org): add jotai SetAtom section
gwansikk Jul 14, 2024
46d101b
docs(suspensive.org): add jotai motivation section
gwansikk Jul 14, 2024
20bc5b5
docs(suspensive.org): fix typo in motivation
gwansikk Jul 14, 2024
019b55b
docs(suspensive.org): fix link in motivation
gwansikk Jul 14, 2024
851109d
docs(suspensive.org): update motivation section
gwansikk Jul 14, 2024
ee67e47
docs(suspensive.org): update docs for jotai
gwansikk Jul 14, 2024
5e9a9eb
Merge branch 'main' into docs/feat/jotai
manudeli Jul 14, 2024
d9943f0
docs(suspensive.org): update jotai docs for feedback
gwansikk Jul 14, 2024
ca3b941
docs(suspensive.org): update jotai order
gwansikk Jul 14, 2024
d7b2c67
Update docs/suspensive.org/src/pages/docs/_meta.en.json
manudeli Jul 14, 2024
c3170a6
Update docs/suspensive.org/src/pages/docs/_meta.ko.json
manudeli Jul 14, 2024
c083b0a
docs(suspensive.org): update async function in Atom
gwansikk Jul 14, 2024
4d69530
Update docs/suspensive.org/src/pages/docs/jotai/motivation.en.mdx
gwansikk Jul 14, 2024
370a415
Update docs/suspensive.org/src/pages/docs/jotai/motivation.en.mdx
gwansikk Jul 14, 2024
542a320
docs(suspensive.org): update jotai docs
gwansikk Jul 15, 2024
66237c1
Merge branch 'main' into docs/feat/jotai
manudeli Jul 15, 2024
204f92f
Merge branch 'main' into docs/feat/jotai
manudeli Jul 15, 2024
ae3eb33
Merge branch 'main' into docs/feat/jotai
manudeli Jul 15, 2024
02c558b
docs(suspensive.org): update motivation section
gwansikk Jul 15, 2024
cea792c
docs(suspensive.org): update component section
gwansikk Jul 15, 2024
c8e11ec
docs(suspensive.org): improve document clarity
gwansikk Jul 16, 2024
e9daead
Merge branch 'main' into docs/feat/jotai
manudeli Jul 17, 2024
404b9b2
docs(suspensive.org): improve document clarity
gwansikk Jul 17, 2024
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
1 change: 1 addition & 0 deletions docs/suspensive.org/src/pages/docs/_meta.en.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
},
"react": "@suspensive/react",
"react-query": "@suspensive/react-query",
"jotai": "@suspensive/jotai",
"react-await": {
"title": "@suspensive/react-await",
"theme": {
Expand Down
1 change: 1 addition & 0 deletions docs/suspensive.org/src/pages/docs/_meta.ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
},
"react": "@suspensive/react",
"react-query": "@suspensive/react-query",
"jotai": "@suspensive/jotai",
"react-await": {
"title": "@suspensive/react-await",
"theme": {
Expand Down
57 changes: 57 additions & 0 deletions docs/suspensive.org/src/pages/docs/jotai/Atom.en.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { Callout } from '@/components'

# Atom

<Callout type='experimental'>

`<Atom/>` is experimental feature, this interfaces could be changed

</Callout>

The Atom component provides the same props interface as Jotai's [useAtom](https://jotai.org/docs/core/use-atom#useatom) hook and can be used declaratively.

### props.atom

You can use Jotai's atom as is.

```tsx /Atom/
import { Atom } from '@suspensive/jotai'
import { atom } from "jotai";

const countAtom = atom(1);

const Example = () => (
<Atom atom={countAtom}>
{([count, setCount]) => (
<>
<div>count: {count}</div>
<button onClick={() => setCount(count + 1)}>+1</button>
</>
)}
</Atom>
)
```

For Async Atom, you can handle the loading state using Suspense.

```tsx /Atom/
import { Atom } from '@suspensive/jotai'
import { Suspense } from '@suspensive/react'
import { atom } from "jotai";

const countAtom = atom(1)
const asyncDoubleCountAtom = atom(async (get) => {
await delay(2000)
return get(countAtom) * 2
})

const Example = () => (
<Suspense fallback={'pending...'}>
<Atom atom={asyncDoubleCountAtom}>
{([count]) => (
<>count: {count}</>
)}
</Atom>
</Suspense>
)
```
gwansikk marked this conversation as resolved.
Show resolved Hide resolved
108 changes: 108 additions & 0 deletions docs/suspensive.org/src/pages/docs/jotai/Atom.ko.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import { Callout } from '@/components'

# Atom

<Callout type='experimental'>

`<Atom/>`는 실험 기능이므로 이 인터페이스는 변경될 수 있습니다.

</Callout>

Atom 컴포넌트는 Jotai의 [useAtom](https://jotai.org/docs/core/use-atom#useatom) 훅과 동일한 인터페이스를 Props로 제공하며 선언적으로 사용할 수 있습니다.

### props.atom

Jotai의 atom을 그대로 사용할 수 있습니다.

```tsx /Atom/
import { Atom } from '@suspensive/jotai'
import { atom } from "jotai";

const countAtom = atom(1);

const Example = () => (
<Atom atom={countAtom}>
{([count, setCount]) => (
<>
<div>count: {count}</div>
<button onClick={() => setCount(count + 1)}>+1</button>
</>
)}
</Atom>
)
```

Async Atom일 경우 Suspense를 사용하여 로딩 상태를 처리할 수 있습니다.

```tsx /Atom/
import { Atom } from '@suspensive/jotai'
import { Suspense } from '@suspensive/react'
import { atom } from "jotai";

const countAtom = atom(1)
const asyncDoubleCountAtom = atom(async (get) => {
await delay(2000)
return get(countAtom) * 2
})

const Example = () => (
<Suspense fallback={'pending...'}>
<Atom atom={asyncDoubleCountAtom}>
{([count]) => (
<>count: {count}</>
)}
</Atom>
</Suspense>
)
```

### 동기

상위 컴포넌트에서 useAtom이 명확하게 드러나지 않습니다. 하위에 선언된 컴포넌트가 내부적으로 어떤 Atom을 사용하고, Suspense를 발생할지 예상하기 어렵습니다.

```tsx
// payment/page.tsx
import { Atom } from '@suspensive/jotai'
import { Suspense } from '@suspensive/react'
import { UserInfo, ShoppingCart } from '~/components'

const PaymentPage = () => (
<Suspense fallback={'pending...'}>
<UserInfo /> {/* 내부적으로 Atom을 사용하는지, Suspense를 발생할지 예상하기 어렵습니다. */}
<ShoppingCart /> {/* 내부적으로 Atom을 사용하는지, Suspense를 발생할지 예상하기 어렵습니다. */}
gwansikk marked this conversation as resolved.
Show resolved Hide resolved
</Suspense>
)
```

```tsx
// payment/components/UserInfo.tsx
import { useAtomValue } from '@suspensive/jotai'
import { Suspense } from '@suspensive/react'
import { UserAddress } from '~/components'
import { userAsyncAtom } from "~/atoms";

// 이 컴포넌트를 사용하는 입장에서 UserInfo라는 이름만으로 내부적으로 어떤 Atom을 사용하고, Suspense를 발생할지 예상하기 어렵습니다.
gwansikk marked this conversation as resolved.
Show resolved Hide resolved
const UserInfo = () => {
const data = useAtomValue(userAsyncAtom)

return <UserAddress {...data} />
}
```

```tsx
// payment/components/ShoppingCart.tsx
import { Atom } from '@suspensive/jotai'
import { Suspense } from '@suspensive/react'
import { shoppingCartAtom } from "~/atoms";

// 이 컴포넌트를 사용하는 입장에서 ShoppingCart라는 이름만으로 내부적으로 어떤 Atom을 사용하고, Suspense를 발생할지 예상하기 어렵습니다.
gwansikk marked this conversation as resolved.
Show resolved Hide resolved
const ShoppingCart = () => {
const [data] = useAtom(shoppingCartAtom)

return (
<>
{data.map(item => <ShoppingItem key={item.id} {...item} />)}
</>
)
}
```
54 changes: 54 additions & 0 deletions docs/suspensive.org/src/pages/docs/jotai/AtomValue.en.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { Callout } from '@/components'

# AtomValue

<Callout type='experimental'>

`<AtomValue/>` is experimental feature, this interfaces could be changed

</Callout>

The AtomValue component provides the same props interface as Jotai's [useAtomValue](https://jotai.org/docs/core/use-atom#useatomvalue) hook and can be used declaratively.

### props.atom

You can use Jotai's atom as is.

```tsx /AtomValue/
import { AtomValue } from '@suspensive/jotai'
import { atom } from "jotai";

const countAtom = atom(1);

const Example = () => (
<AtomValue atom={countAtom}>
{(count) => (
<>count: {count}</>
)}
</AtomValue>
)
```

For Async Atom, you can handle the loading state using Suspense.

```tsx /AtomValue/
import { AtomValue } from '@suspensive/jotai'
import { Suspense } from '@suspensive/react'
import { atom } from "jotai";

const countAtom = atom(1)
const asyncDoubleCountAtom = atom(async (get) => {
await delay(2000)
return get(countAtom) * 2
})

const Example = () => (
<Suspense fallback={'pending...'}>
<AtomValue atom={asyncDoubleCountAtom}>
{(count) => (
<>count: {count}</>
)}
</AtomValue>
</Suspense>
)
```
gwansikk marked this conversation as resolved.
Show resolved Hide resolved
58 changes: 58 additions & 0 deletions docs/suspensive.org/src/pages/docs/jotai/AtomValue.ko.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { Callout } from '@/components'

# AtomValue

<Callout type='experimental'>

`<AtomValue/>`는 실험 기능이므로 이 인터페이스는 변경될 수 있습니다.

</Callout>

AtomValue 컴포넌트는 Jotai의 [useAtomValue](https://jotai.org/docs/core/use-atom#useatomvalue) 훅과 동일한 인터페이스를 Props로 제공하며 선언적으로 사용할 수 있습니다.

### props.atom

Jotai의 atom을 그대로 사용할 수 있습니다.

```tsx /AtomValue/
import { AtomValue } from '@suspensive/jotai'
import { atom } from "jotai";

const countAtom = atom(1);

const Example = () => (
<AtomValue atom={countAtom}>
{(count) => (
<>count: {count}</>
)}
</AtomValue>
)
```

Async Atom일 경우 Suspense를 사용하여 로딩 상태를 처리할 수 있습니다.

```tsx /AtomValue/
import { AtomValue } from '@suspensive/jotai'
import { Suspense } from '@suspensive/react'
import { atom } from "jotai";

const countAtom = atom(1)
const asyncDoubleCountAtom = atom(async (get) => {
await delay(2000)
return get(countAtom) * 2
})

const Example = () => (
<Suspense fallback={'pending...'}>
<AtomValue atom={asyncDoubleCountAtom}>
{(count) => (
<>count: {count}</>
)}
</AtomValue>
</Suspense>
)
```

### 동기

[`<Atom/>`](https://suspensive.org/ko/docs/jotai/Atom)의 동기와 같이 `<AtomValue/>` 또한, 상위 컴포넌트에서 명확하게 드러나지 않습니다. 하위에 선언된 컴포넌트가 내부적으로 어떤 Atom을 사용하고, Suspense를 발생할지 예상하기 어렵습니다.
53 changes: 53 additions & 0 deletions docs/suspensive.org/src/pages/docs/jotai/SetAtom.en.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { Callout } from '@/components'

# SetAtom

<Callout type='experimental'>

`<SetAtom/>` is experimental feature, this interfaces could be changed

</Callout>

The SetAtom component provides the same props interface as Jotai's [useSetAtom](https://jotai.org/docs/core/use-atom#usesetatom) hook and can be used declaratively.

### props.atom

You can use Jotai's atom as is.

```tsx /SetAtom/
import { SetAtom } from '@suspensive/jotai'
import { atom } from "jotai";

const switchAtom = atom(false)

const Example = () => (
<SetAtom atom={switchAtom}>
{(setCount) => (
<>
<button onClick={() => setCount(true)}>Set True</button>
<button onClick={() => setCount(false)}>Set False</button>
</>
)}
</SetAtom>
)
```

For Async Atom, Suspense is triggered until the Promise is resolved.

```tsx /SetAtom/
import { SetAtom } from '@suspensive/jotai'
import { atom } from "jotai";

const request = async () => fetch('https://...').then((res) => res.json())
const baseAtom = atom(0)

const Example = () => (
<SetAtom atom={baseAtom}>
{(setValue) => (
<>
<button onClick={() => setValue(request())}>request</button> // Suspend is triggered until the promise is resolved.
</>
)}
</SetAtom>
)
```
Loading
Loading