Team Chat Powered by PubNub

Team Chat Powered by PubNub

    ›Tutorial

    Quickstart

    • Introduction
    • Run Locally
    • Advanced Features

    Tutorial

    • Overview
    • Setup Theming
    • Add PubNub Keys
    • Populate Data
    • Login
    • Show User Details
    • Show Conversations
    • Send Messages
    • Join Conversation
    • Leave Conversation
    • Show Members
    • Send Typing Indicators
    • Profanity Filter

    Add PubNub to your App

    When the app first loads, it runs the main/App.tsx component to initialize the pubnub client with your publish and subscribe keys that are configured in the .env file.

    The component also calls pubnub.addListener() to register all listeners at once (message listener, presence listener, and so on). The listener triggers events when the app receives messages, and automatically dispatches reducers to update the local store.

    import Pubnub from "pubnub";
    import { createPubNubListener } from "pubnub-redux";
    import { PubNubProvider } from "pubnub-react";
    import keyConfiguration from "config/pubnub-keys";
    const pubnubConfig = Object.assign(
      {},{
        restore: true,
        heartbeatInterval: 0
      },
      keyConfiguration
    );
    const pubnub = new Pubnub(pubnubConfig);
    const App = () => {
      useEffect(() => {
        pubnub.addListener(createPubNubListener(store.dispatch));
        return leaveApplication;
      }, []);
      
      return (
        <Provider store={store}>
          <PubNubProvider client={pubnub}>
            <Normalize />
            <GlobalStyles />
            <ApplicationRouter />
          </PubNubProvider>
        </Provider>
      );
    };
      
    export { App };
    
    ← Setup ThemingPopulate Data →
    Docs
    QuickstartTutorialThemeingPubNub Chat
    Source
    GitHubStar
    PubNub
    Copyright © 2020 PubNub