agora-react-native-rtm
Version:
React Native around the Agora RTM SDKs for Android and iOS agora
23 lines • 718 B
JavaScript
import { useContext } from 'react';
import React, { createContext } from 'react';
export const AgoraRTMContext = /* @__PURE__ */createContext(null);
export function RTMProvider({
client,
children
}) {
return /*#__PURE__*/React.createElement(AgoraRTMContext.Provider, {
value: client
}, children);
}
function useOptionalRTM(client) {
const clientFromContext = useContext(AgoraRTMContext);
return client || clientFromContext;
}
export function useRtm(client) {
const resolvedClient = useOptionalRTM(client);
if (!resolvedClient) {
throw new Error('Agora RTM client not found. Should be wrapped in <RTMProvider value={client} />');
}
return resolvedClient;
}
//# sourceMappingURL=useRtm.js.map