import React, { useEffect, useState } from "react";

const DeviceData = () => {
  const [deviceData, setDeviceData] = useState("");
  const [error, setError] = useState(null);

  useEffect(() => {
    const fetchData = async () => {
      try {
        const response = await fetch("/api/fetchDeviceData");
        if (!response.ok) {
          throw new Error(`Fehler beim Abrufen der Daten: ${response.status}`);
        }
        const data = await response.json();
        setDeviceData(data.content); // Die Daten aus der API-Antwort setzen
      } catch (error) {
        setError(error.message);
      }
    };

    fetchData();
  }, []);

  return (
    <div>
      {error ? (
        <p>Fehler: {error}</p>
      ) : (
        <div dangerouslySetInnerHTML={{ __html: deviceData }} />
      )}
    </div>
  );
};

export default DeviceData;
