PubNub Consumer

A PubNubConsumer allows you to access the client instance you made available with a PubNubProvider.

PubNubConsumer props

The PubNubConsumer component takes a single prop: client is the required pubNubClient instance. This is used by all components that require PubNub functionality.

PubNubConsumer example

Once you've created a PubNubProvider, you can access the client with a PubNubConsumer:

import React from 'react';
import PubNub from 'pubnub';
import { PubNubProvider } from '../PubNubProvider';
import { PubNubConsumer } from '../PubNubConsumer';
import { getPubNubContext } from '../PubNubContext';

const pubNubConfig = require('../config/pubnub.json');
const pubNubClient = new PubNub(pubNubConfig.Demo.keySet);

const App = () => {
<PubNubProvider client={pubNubClient}>
{client => "success!" /* do something now */ }
show all 16 lines
Last updated on