import React, { useCallback, useEffect, useState } from "react"; import useWebSocket, { ReadyState } from "react-use-websocket"; function App() { const [socketUrl, setSocketUrl] = useState("ws://127.0.0.1:8080/ws"); const [messageHistory, setMessageHistory] = useState([]); const { sendMessage, lastMessage, readyState } = useWebSocket(socketUrl); const handleClickSendMessage = useCallback(() => { sendMessage("Hello"); }, []); console.info(lastMessage); return (
{lastMessage?.data ?? ""}
); } export default App;