I am trying to parse data from the client to the server, but somehow I'm getting undefined
for the data. Can you give your thought on why this is behaving this way?
const handler = async (req, res) => {
const {data} = req.body;
if (req.method === "POST") {
try {
console.log(data) // Retuned `undefined`
res.status(200).json({ message: "okay" })
} catch (error) {
console.error("Error occurred:", error.message);
res.status(500).json({ error: "An error occurred while processing your request." });
}
}
};
export default handler;