How to handle client data on server?
Unanswered
Manx posted this in #help-forum
ManxOP
I have a hook to get some data, and I should send this data to server to validate it. How do I use client hook to get data and make an asynchronous request after hat? I have an idea to wrap it all in useEffect hook, but maybe is there another ways to do it?
18 Replies
@Manx I have a hook to get some data, and I should send this data to server to validate it. How do I use client hook to get data and make an asynchronous request after hat? I have an idea to wrap it all in useEffect hook, but maybe is there another ways to do it?
Use api routes to send data from client to server side
You can learn more about it at nextjs documentation
@Anay-208 Use api routes to send data from client to server side
ManxOP
Is it possible to use hooks there? Because data I need to send on server goes from hook
You can’t use hooks on server side
ManxOP
this is the component, where I get data from useInitData hook. And I should send this data on server
And create route.ts At that path
Is your issue resolved
Hey @Manx, I'm awaiting a reply on your end regarding this issue.
If your issue is resolved, you can ignore this message!
If your issue is resolved, you can ignore this message!
@Anay-208 Hey <@1169019501195575316>, I'm awaiting a reply on your end regarding this issue.
If your issue is resolved, you can ignore this message!
ManxOP
Hi, actually not, I leave it in useEffect hook. Didn’t find the best way
@Manx Hi, actually not, I leave it in useEffect hook. Didn’t find the best way
The only way to pass data from client to server is route.ts
@Anay-208 The only way to pass data from client to server is route.ts
ManxOP
But how to send a request on api and handle it (async await) if I get this data to send from hook
See the documentation about api
And you can get the response and set it on useState
@Anay-208 Create a /api/route.ts
ManxOP
I do it here
@Manx I do it here
Yup, you are getting the data here. Can you send content of api/route.ts