import { useState, useEffect } from "react";
import { API_URL } from "../config";
export default function RandomMsg() {
const [randomMsg, setRandomMsg] = useState("");
const getRandomMsg = async () => {
try {
const response = await fetch(`${API_URL}/randmsg`, {
method: "POST",
headers: { "Content-Type": "application/json; charset=utf-8" },
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
const data = await response.json();
if (data?.msg) setRandomMsg(data.msg.replace(/
/gi, "\n"));
} catch (err) {
console.error("Failed to fetch random message:", err);
}
};
useEffect(() => void getRandomMsg(), []);
return (