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:

1import React from 'react';
2import PubNub from 'pubnub';
3import { PubNubProvider } from '../PubNubProvider';
4import { PubNubConsumer } from '../PubNubConsumer';
5import { getPubNubContext } from '../PubNubContext';
6
7const pubNubConfig = require('../config/pubnub.json');
8const pubNubClient = new PubNub(pubNubConfig.Demo.keySet);
9
10const App = () => {
11 <PubNubProvider client={pubNubClient}>
12 <PubNubConsumer>
13 {client => "success!" /* do something now */ }
14 </PubNubConsumer>
15 </PubNubProvider>
show all 16 lines
Last updated on