database write on button click

How do I do it? I can't use trpc(can only make calls at top level), I could make an api endpoint, I tried, it's kind of awkward and looks like this:
const callAPI = async () => {
try {
const res = await fetch(`http://localhost:3000/api/cookbook/create`, {
method: "post",
body: JSON.stringify(state),
});
console.log(res);
} catch (err) {
console.log(err);
}
};
const callAPI = async () => {
try {
const res = await fetch(`http://localhost:3000/api/cookbook/create`, {
method: "post",
body: JSON.stringify(state),
});
console.log(res);
} catch (err) {
console.log(err);
}
};
I manage a ts type through useState. The user modifies that state and at the end, I want to upload that state to the database on the press of a button.
4 Replies
Johnson
JohnsonOP3y ago
(using prisma)
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Johnson
JohnsonOP3y ago
thx!
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server