@@ -15,14 +15,15 @@ function useUntil<T extends (...args: any[]) => Promise<any>>(fn: T, options: Ba
1515 const [ err , setErr ] = React . useState < Error | undefined > ( ) ;
1616
1717 const action = React . useRef (
18- until ( async ( props ) => {
18+ until ( async ( ... props : Parameters < T > [ ] ) => {
1919 if ( forceStop . current ) {
2020 forceStopCallback . current && forceStopCallback . current ( ) ;
2121 return forceStop . current ;
2222 }
2323 try {
2424 setErr ( undefined ) ;
25- const res = await fn ( props ) ;
25+ // eslint-disable-next-line prefer-spread
26+ const res = await fn . apply ( null , props ) ;
2627 setResult ( res ) ;
2728 } catch ( error ) {
2829 setErr ( error as Error ) ;
@@ -44,18 +45,17 @@ function useUntil<T extends (...args: any[]) => Promise<any>>(fn: T, options: Ba
4445 } , [ ] ) ;
4546
4647 const run = React . useCallback (
47- async ( props : any , options ?: { once ?: boolean } ) => {
48+ async ( ... props : Parameters < T > ) => {
4849 if ( isRunning . current ) {
4950 await cancel ( ) ;
5051 }
5152 isRunning . current = true ;
52- action . current ( props ) ;
53- options ?. once && cancel ( ) ;
53+ return action . current . apply ( null , props ) ;
5454 } ,
5555 [ cancel , action ] ,
56- ) ;
56+ ) as T ;
5757
58- return { result, run, cancel, err } ;
58+ return { result, run, cancel, isRunning , err } ;
5959}
6060
6161export default useUntil ;
0 commit comments