Back

Version 34

9/10/2024
/** @jsxImportSource https://esm.sh/react */
import React, { useState } from "https://esm.sh/react";
import { createRoot } from "https://esm.sh/react-dom/client";

function App() {
const [input, setInput] = useState({
storyTitle: "",
storyText: "",
});
const [result, setResult] = useState(null);
const [loading, setLoading] = useState(false);

const handleSubmit = async (e) => {
e.preventDefault();
setLoading(true);

try {
const response = await fetch("/", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(input),
});

if (!response.ok) {
throw new Error("Network response was not ok");
}
const data = await response.json();
setResult(data);
} catch (error) {
console.error("Error:", error);
} finally {
setLoading(false);
}
};

return (