Next.js Discord

Discord Forum

useActionState returns array of 3 values?

Answered
Florida White posted this in #help-forum
Open in Discord
Florida WhiteOP
Hi all, I am following the Next JS tutorial and have reached the part of adding authentication.
https://nextjs.org/learn/dashboard-app/adding-authentication

I am trying to understand why the useActionState returns an array of 3 values?
const [errorMessage, formAction, isPending] = useActionState(
    authenticate,
    undefined,
  );


I thought it could only return 2: https://react.dev/reference/react/useActionState

My code works, I am just trying to understand what I c/p'ed. 😅
Answered by joulev
good question. i'm pretty sure react plans for the hook to return 3 items, but at the moment the isPending part has not been implemented yet (always return false iirc), so the official react documentation only documents the first two items.

you can log isPending to see if it is ever truthy. the code in the learn tutorial only uses isPending with aria-disabled so whether it works or not is not immediately apparent. i'm pretty sure the aria-disabled doesn't work.
View full answer

2 Replies

@Florida White Hi all, I am following the Next JS tutorial and have reached the part of adding authentication. https://nextjs.org/learn/dashboard-app/adding-authentication I am trying to understand why the useActionState returns an array of 3 values? const [errorMessage, formAction, isPending] = useActionState( authenticate, undefined, ); I thought it could only return 2: https://react.dev/reference/react/useActionState My code works, I am just trying to understand what I c/p'ed. 😅
good question. i'm pretty sure react plans for the hook to return 3 items, but at the moment the isPending part has not been implemented yet (always return false iirc), so the official react documentation only documents the first two items.

you can log isPending to see if it is ever truthy. the code in the learn tutorial only uses isPending with aria-disabled so whether it works or not is not immediately apparent. i'm pretty sure the aria-disabled doesn't work.
Answer
Florida WhiteOP
Thanks for affirming my confusion haha