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 11import React from "react"
2- import { useAsync } from "react-async"
2+ import { useAsync , IfPending , IfFulfilled , IfRejected } from "react-async"
33import ReactDOM from "react-dom"
44import DevTools from "react-async-devtools"
55import "./index.css"
@@ -27,15 +27,16 @@ const UserDetails = ({ data }) => (
2727)
2828
2929const 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
4142export const App = ( ) => (
You can’t perform that action at this time.
0 commit comments