Skip to content
Ekaansh Arora edited this page Feb 16, 2022 · 2 revisions

Agora RTM SDK React Wrapper

A react (react.js) wrapper for Agora RTM SDK.

Install

npm install agora-rtm-react

Usage

import React from 'react'
import { createChannel, createClient, RtmMessage } from 'agora-rtm-react'

const useClient = createClient('<Agora App ID>');
const useChannel = createChannel('channelName')

const App = () => {
  const client = useClient();
  const testChannel = useChannel(client)

  const login = async () => {
    await client.login({ uid: 'userId' })
    await testChannel.join()
  }
  
  const sendMsg = async (text: string) => {
    const message = client.createMessage({ text, messageType: 'TEXT' })
    await testChannel.sendMessage(message)
  }
...
}

Example

A chat example using the wrapper can be found here.

Reference

You can view the methods in the wrapper here.

Clone this wiki locally