File tree Expand file tree Collapse file tree 1 file changed +13
-7
lines changed Expand file tree Collapse file tree 1 file changed +13
-7
lines changed Original file line number Diff line number Diff line change @@ -47,19 +47,25 @@ export interface Options {
4747
4848type InnerPromiseType = Promise < boolean | DispatchAsyncResult >
4949
50+ // 👉 backward compatibility
51+ export function useCompatDispatchAsync < R = any > (
52+ action ?: Action ,
53+ ) : CompatActionResult < R > {
54+ const dispatch = useDispatch ( )
55+ if ( action ) {
56+ return ( ) => dispatchAsync < R > ( dispatch , action )
57+ }
58+ return ( action : Action ) => dispatchAsync < R > ( dispatch , action )
59+ }
60+
5061// the hook
5162export function useDispatchAsync < R = any > (
52- actionFunction ? : ( ...args : any [ ] ) => Action & { payload : any } ,
63+ actionFunction : ( ...args : any [ ] ) => Action & { payload : any } ,
5364 deps : any [ ] = [ ] ,
5465 options : Options = { timeoutInMilliseconds : 15000 } , // wait 15s
55- ) : UseDispatchAsync < R > | CompatActionResult < R > {
66+ ) : UseDispatchAsync < R > {
5667 const dispatch = useDispatch ( )
5768
58- // 👉 backward compatibility
59- if ( ! actionFunction ) {
60- return ( action : Action ) => dispatchAsync < R > ( dispatch , action )
61- }
62-
6369 // 👉 Better flow with informative & useful return
6470 const [ result , setResult ] = useState < R | undefined > ( undefined )
6571 const [ error , setError ] = useState < Error | undefined > ( undefined )
You can’t perform that action at this time.
0 commit comments