File tree Expand file tree Collapse file tree 2 files changed +11
-3
lines changed
Expand file tree Collapse file tree 2 files changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -81,7 +81,9 @@ const useAsync = (opts, init) => {
8181}
8282
8383const unsupported = ( ) => {
84- throw new Error ( "useAsync requires react@16.7.0 or later" )
84+ throw new Error (
85+ "useAsync requires react@16.7.0 or later. Upgrade your React version or use the <Async> component instead."
86+ )
8587}
8688
8789export default ( useState ? useAsync : unsupported )
Original file line number Diff line number Diff line change 11import * as React from "react"
22
33type AsyncChildren < T > = ( ( state : AsyncState < T > ) => React . ReactNode ) | React . ReactNode
4+ type PromiseFn < T > = ( props : object ) => Promise < T >
45
5- interface AsyncProps < T > {
6- promiseFn ?: ( props : object ) => Promise < T >
6+ interface AsyncOptions < T > {
7+ promiseFn ?: PromiseFn < T >
78 deferFn ?: ( ...args ) => Promise < T >
89 watch ?: any
910 initialValue ?: T
1011 onResolve ?: ( data : T ) => void
1112 onError ?: ( error : Error ) => void
13+ }
14+
15+ interface AsyncProps < T > extends AsyncOptions < T > {
1216 children ?: AsyncChildren < T >
1317}
1418
@@ -37,4 +41,6 @@ declare namespace Async {
3741
3842declare function createInstance < T > ( defaultProps ?: AsyncProps < T > ) : Async < T >
3943
44+ export function useAsync < T > ( opts : AsyncOptions < T > | PromiseFn < T > , init ?: T ) : AsyncState < T >
45+
4046export default createInstance
You can’t perform that action at this time.
0 commit comments