I'm using Nextjs 13 with server actions. I have a form:
const [isUploadingDocs, setIsUploadingDocs] = useState<boolean>(false);
... rest of code ...
return (
<form
action={async (formData) => {
setIsUploadingDocs(true)
upload(formData).then((response) => {
setIsUploadingDocs(false)
})
}}>
)
I am never able to capture the state change within the above action. I've also tried useRef
, and while that worked within the function, it did not trigger react's digest cycle, so my elements depending on the ref.current
value were unchanged.
I read the documentation here and also tried useFormStatus
, which also did not work as expected in my implementation. I'd rather just use useState
if possible.
Is this a bug with nextjs 13 or expected?
useFormStatus
was a child of the form? – Sogdian