1connect to the socket server on component mount with useEffect
2save each new incoming message in the component's state.
3
4function App() {
5 const [response, setResponse] = useState("");
6
7 useEffect(() => {
8 const socket = socketIOClient(ENDPOINT);
9 socket.on("FromAPI", data => {
10 setResponse(data);
11 });
12 }, []);
13
14 return (
15 <p>
16 It's <time dateTime={response}>{response}</time>
17 </p>
18 );
19}