import { Types } from "ably"; import React, { useState } from "react"; import { configureAbly, useChannel, usePresence } from "../../src/index"; import "./App.css"; configureAbly({ key: import.meta.env.VITE_ABLY_API_KEY, clientId: generateRandomId() }); function App() { const [messages, updateMessages] = useState([]); const [channel, ably] = useChannel("your-channel-name", (message) => { updateMessages((prev) => [...prev, message]); }); const [presenceData, updateStatus] = usePresence("your-channel-name", { foo: "bar" }, (update) => { console.log(update); }); const messagePreviews = messages.map((msg, index) =>
  • {msg.data.text}
  • ); const presentClients = presenceData.map((msg, index) => (
  • {msg.clientId}: {JSON.stringify(msg.data)}
  • )); return (
    Ably React Hooks Demo

    Messages

    Present Clients

    ); } function generateRandomId() { return Math.random().toString(36).substr(2, 9); } export default App;