File tree Expand file tree Collapse file tree 1 file changed +11
-10
lines changed Expand file tree Collapse file tree 1 file changed +11
-10
lines changed Original file line number Diff line number Diff line change 1
1
import React from "react"
2
- import { useAsync } from "react-async"
2
+ import { useAsync , IfPending , IfFulfilled , IfRejected } from "react-async"
3
3
import ReactDOM from "react-dom"
4
4
import DevTools from "react-async-devtools"
5
5
import "./index.css"
@@ -27,15 +27,16 @@ const UserDetails = ({ data }) => (
27
27
)
28
28
29
29
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
+ )
39
40
}
40
41
41
42
export const App = ( ) => (
You can’t perform that action at this time.
0 commit comments