Reset the state of useActionState #75365
Replies: 3 comments 1 reply
-
May I ask, why do you need to reset it? that state value is whatever your action returned last. Resetting it, feels unnecessary in the use case you shared. |
Beta Was this translation helpful? Give feedback.
-
I'm having a similar issue where I'm incrementing a value in an effect or displaying an error based on whether the action was a success or not. It's causing an infinite loop and I haven't found a nice way around it. Setting It would be nicer to be able to reset the state once the response has been handled, since the form is being used in a component that stays mounted and the form itself is reset each time it is submitted. |
Beta Was this translation helpful? Give feedback.
-
i'm also facing a scenario that need to reset state of useActionState. When submitted form to action and doing some validation, return error state when failed and show the error message under input box. Then i need to hide error message when user change the invalid input data to new value. currently i need to create submitted state and use the useEffect to watch state change then update submitted to true and need to add onChange on every input to reset submitted state to false using to control the error message display. |
Beta Was this translation helpful? Give feedback.
-
Summary
Is there a way to reset the state of the useActionState? I'm using the state like the example below, and once the
deleteDate.success
turns to true, it stays there. Is there a way to turn it back? The only way I found is thisdeleteState.success = false; // Reset success state
, but I'm not sure if that's a bad way to go about it.Additional information
No response
Example
No response
Beta Was this translation helpful? Give feedback.
All reactions