How do I access server actions return data?
Answered
Rhinelander posted this in #help-forum
RhinelanderOP
My action fetches api and returns url.
I want to access that url in my component.
How do I do that?
I want to access that url in my component.
How do I do that?
26 Replies
Araucanian herring
please you post a example about this.
@Rhinelander My action fetches api and returns url.
I want to access that url in my component.
How do I do that?
const url = await serverAction()
console.log(url)
console.log(url)
If you use the action={…} prop, then have a look at useActionState (previously named useFormState)
RhinelanderOP
I have this form that uses action
this action returns url
and i want to redirect to that url
but i can't to that in action
if i try window.location.href it doesn't exists
if i try redirect i get nextredirect error
Now i want to get that action url and redirect inside component
and yeah url is external
not just path inside my project
I know how to solve this with simple post request but amount of code needed inside component is just not clean looking
RhinelanderOP
In short
This does not work
as i get this error
This is caused because of return in catch
just found out
but still doesn't work
On click it doest redirect me
on my button i can see pending state
it is executing it
@Rhinelander In short
Do not catch redirect
Answer
It throws an error that must not be caught
RhinelanderOP
it works thanks