生命周期
Last updated
Last updated
// Some code
function ChatRoom({ roomId /* "general" */ }) {
useEffect(() => {
const connection = createConnection(serverUrl, roomId); // 连接到 "general" 聊天室
connection.connect();
return () => {
connection.disconnect(); // 断开与 "general" 聊天室的连接
};
// ...