Do JSX API routes exist for using React Email in the backend?
Unanswered
Griffon Nivernais posted this in #help-forum
Griffon NivernaisOP
I'm wondering if the following is possible for use in an API route:
https://react.email/docs/utilities/render#3-convert-to-html
I'm aware that you can export emails, which gives JS and not HTML, and wanted to know if the above was possible through an
https://react.email/docs/utilities/render#3-convert-to-html
I'm aware that you can export emails, which gives JS and not HTML, and wanted to know if the above was possible through an
api/route.jsx approach.9 Replies
@alfon why not?
Griffon NivernaisOP
Because I can't find anything in the docs that mentions defining API routes using the
.jsx file extension.@Griffon Nivernais Because I can't find anything in the docs that mentions defining API routes using the `.jsx` file extension.
wdym by "aware that you can export emails, which gives JS"? did you meant that if you export emails with API handler it will return JS?
Griffon NivernaisOP
When I use React Email, it allows me to export components as JS.
well why don't you create a page.jsx then? or implement it there haha
Griffon NivernaisOP
I don't think I follow. I'm trying to make an email template so that I can use that to send emails*.
Griffon NivernaisOP
Okay, I guess it works with just
.js files and I only just found this out now. ðŸ˜Thank you for your help nonetheless.
How I tested it
import { render } from "@react-email/render";
import Email from "@/emails/Email";
export default function handler(req, res) {
res.status(200).send(render(<Email />));
}