Is there any way to use post body in page.tsx?
Answered
Japanese common catfish posted this in #help-forum
Japanese common catfishOP
I'd like to use post body in page.tsx (not route.ts)
Please let me know if it's possible or not
Please let me know if it's possible or not
Answered by Polar bear
You should store the data in a state or use react hook form. Then create a function that handles the form submission. Once you get the data from the state you do whatever you need, maybe a server action is what you need if you want to perform any db related action. If its just the ui, do what you need to do inside the function that handles the form submission
4 Replies
Polar bear
Hey! Could you provide more context about it?
@Polar bear Hey! Could you provide more context about it?
Japanese common catfishOP
I would like to submit the form data by POST method.
<form method="post" action="/blahblah">
...
</form>
and in "/blahblah/page.tsx", I want to use the input data
<form method="post" action="/blahblah">
...
</form>
and in "/blahblah/page.tsx", I want to use the input data
Polar bear
You should store the data in a state or use react hook form. Then create a function that handles the form submission. Once you get the data from the state you do whatever you need, maybe a server action is what you need if you want to perform any db related action. If its just the ui, do what you need to do inside the function that handles the form submission
Answer
not possible to get post body in page.tsx files. the post method of page routes is reserved for server actions