@@ -31,20 +31,23 @@ export const useAction = <ServerError, S extends StandardSchemaV1 | undefined, C
31
31
const [ clientInput , setClientInput ] = React . useState < InferInputOrDefault < S , void > > ( ) ;
32
32
const [ isExecuting , setIsExecuting ] = React . useState ( false ) ;
33
33
const [ navigationError , setNavigationError ] = React . useState < Error | null > ( null ) ;
34
+ const [ thrownError , setThrownError ] = React . useState < Error | null > ( null ) ;
34
35
const [ isIdle , setIsIdle ] = React . useState ( true ) ;
35
36
36
37
const status = getActionStatus < ServerError , S , CVE , Data > ( {
37
38
isExecuting,
38
39
result,
39
40
isIdle,
40
41
hasNavigated : navigationError !== null ,
42
+ hasThrownError : thrownError !== null ,
41
43
} ) ;
42
44
43
45
const execute = React . useCallback (
44
46
( input : InferInputOrDefault < S , void > ) => {
45
47
setTimeout ( ( ) => {
46
48
setIsIdle ( false ) ;
47
49
setNavigationError ( null ) ;
50
+ setThrownError ( null ) ;
48
51
setClientInput ( input ) ;
49
52
setIsExecuting ( true ) ;
50
53
} , 0 ) ;
@@ -60,6 +63,7 @@ export const useAction = <ServerError, S extends StandardSchemaV1 | undefined, C
60
63
return ;
61
64
}
62
65
66
+ setThrownError ( e as Error ) ;
63
67
throw e ;
64
68
} )
65
69
. finally ( ( ) => {
@@ -76,6 +80,7 @@ export const useAction = <ServerError, S extends StandardSchemaV1 | undefined, C
76
80
setTimeout ( ( ) => {
77
81
setIsIdle ( false ) ;
78
82
setNavigationError ( null ) ;
83
+ setThrownError ( null ) ;
79
84
setClientInput ( input ) ;
80
85
setIsExecuting ( true ) ;
81
86
} , 0 ) ;
@@ -94,6 +99,7 @@ export const useAction = <ServerError, S extends StandardSchemaV1 | undefined, C
94
99
return ;
95
100
}
96
101
102
+ setThrownError ( e as Error ) ;
97
103
reject ( e ) ;
98
104
} )
99
105
. finally ( ( ) => {
@@ -110,6 +116,7 @@ export const useAction = <ServerError, S extends StandardSchemaV1 | undefined, C
110
116
const reset = React . useCallback ( ( ) => {
111
117
setIsIdle ( true ) ;
112
118
setNavigationError ( null ) ;
119
+ setThrownError ( null ) ;
113
120
setClientInput ( undefined ) ;
114
121
setResult ( { } ) ;
115
122
} , [ ] ) ;
@@ -119,6 +126,7 @@ export const useAction = <ServerError, S extends StandardSchemaV1 | undefined, C
119
126
input : clientInput as InferInputOrDefault < S , undefined > ,
120
127
status,
121
128
navigationError,
129
+ thrownError,
122
130
cb,
123
131
} ) ;
124
132
@@ -152,6 +160,7 @@ export const useOptimisticAction = <ServerError, S extends StandardSchemaV1 | un
152
160
const [ clientInput , setClientInput ] = React . useState < InferInputOrDefault < S , void > > ( ) ;
153
161
const [ isExecuting , setIsExecuting ] = React . useState ( false ) ;
154
162
const [ navigationError , setNavigationError ] = React . useState < Error | null > ( null ) ;
163
+ const [ thrownError , setThrownError ] = React . useState < Error | null > ( null ) ;
155
164
const [ isIdle , setIsIdle ] = React . useState ( true ) ;
156
165
const [ optimisticState , setOptimisticValue ] = React . useOptimistic < State , InferInputOrDefault < S , undefined > > (
157
166
utils . currentState ,
@@ -163,6 +172,7 @@ export const useOptimisticAction = <ServerError, S extends StandardSchemaV1 | un
163
172
result,
164
173
isIdle,
165
174
hasNavigated : navigationError !== null ,
175
+ hasThrownError : thrownError !== null ,
166
176
} ) ;
167
177
168
178
const execute = React . useCallback (
@@ -171,6 +181,7 @@ export const useOptimisticAction = <ServerError, S extends StandardSchemaV1 | un
171
181
setIsIdle ( false ) ;
172
182
setClientInput ( input ) ;
173
183
setNavigationError ( null ) ;
184
+ setThrownError ( null ) ;
174
185
setIsExecuting ( true ) ;
175
186
} , 0 ) ;
176
187
@@ -186,6 +197,7 @@ export const useOptimisticAction = <ServerError, S extends StandardSchemaV1 | un
186
197
return ;
187
198
}
188
199
200
+ setThrownError ( e as Error ) ;
189
201
throw e ;
190
202
} )
191
203
. finally ( ( ) => {
@@ -203,6 +215,7 @@ export const useOptimisticAction = <ServerError, S extends StandardSchemaV1 | un
203
215
setIsIdle ( false ) ;
204
216
setClientInput ( input ) ;
205
217
setNavigationError ( null ) ;
218
+ setThrownError ( null ) ;
206
219
setIsExecuting ( true ) ;
207
220
} , 0 ) ;
208
221
@@ -221,6 +234,7 @@ export const useOptimisticAction = <ServerError, S extends StandardSchemaV1 | un
221
234
return ;
222
235
}
223
236
237
+ setThrownError ( e as Error ) ;
224
238
reject ( e ) ;
225
239
} )
226
240
. finally ( ( ) => {
@@ -238,6 +252,7 @@ export const useOptimisticAction = <ServerError, S extends StandardSchemaV1 | un
238
252
setIsIdle ( true ) ;
239
253
setClientInput ( undefined ) ;
240
254
setNavigationError ( null ) ;
255
+ setThrownError ( null ) ;
241
256
setResult ( { } ) ;
242
257
} , [ ] ) ;
243
258
@@ -246,6 +261,7 @@ export const useOptimisticAction = <ServerError, S extends StandardSchemaV1 | un
246
261
input : clientInput as InferInputOrDefault < S , undefined > ,
247
262
status,
248
263
navigationError,
264
+ thrownError,
249
265
cb : {
250
266
onExecute : utils . onExecute ,
251
267
onSuccess : utils . onSuccess ,
0 commit comments