Next.js Discord

Discord Forum

Loading state for server action not called inside a form?

Unanswered
Toyger posted this in #help-forum
Open in Discord
ToygerOP
I have a server action I call from inside a client component, and I wanted to know if there was any way to get the loading state of that request. The client component from where I call the server action doesn't have a form, and neither does the server parent component.

4 Replies

Toyger
theoretically it is simple promise
so instead awaiting result you can try this
const [isLoading,setIsLoading] = useState(false);

......
yourServerAction().then(()=>{
  setIsLoading(false)
})
setIsLoading(true);
......
Can you make it have a form?
Otherwise you can use a useTransition