Skip to content

Commit 28c1f7a

Browse files
committed
Update example to use standalone helpers.
1 parent ad7e594 commit 28c1f7a

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

examples/basic-hook/src/index.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from "react"
2-
import { useAsync } from "react-async"
2+
import { useAsync, IfPending, IfFulfilled, IfRejected } from "react-async"
33
import ReactDOM from "react-dom"
44
import DevTools from "react-async-devtools"
55
import "./index.css"
@@ -27,15 +27,16 @@ const UserDetails = ({ data }) => (
2727
)
2828

2929
const User = ({ userId }) => {
30-
const { data, error, isPending } = useAsync({
31-
promiseFn: loadUser,
32-
debugLabel: `User ${userId}`,
33-
userId,
34-
})
35-
if (isPending) return <UserPlaceholder />
36-
if (error) return <p>{error.message}</p>
37-
if (data) return <UserDetails data={data} />
38-
return null
30+
const state = useAsync({ promiseFn: loadUser, debugLabel: `User ${userId}`, userId })
31+
return (
32+
<>
33+
<IfPending state={state}>
34+
<UserPlaceholder />
35+
</IfPending>
36+
<IfFulfilled state={state}>{data => <UserDetails data={data} />}</IfFulfilled>
37+
<IfRejected state={state}>{error => <p>{error.message}</p>}</IfRejected>
38+
</>
39+
)
3940
}
4041

4142
export const App = () => (

0 commit comments

Comments
 (0)