---
source_url: https://www.pubnub.com/docs/sdks/react/api-reference/consumer
title: PubNub Consumer
updated_at: 2024-06-13T07:29:12.000Z
---

# PubNub Consumer

> For AI agents: documentation index at https://www.pubnub.com/llms-full.txt

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`:

```jsx
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}>
    <PubNubConsumer>
      {client => "success!" /* do something now */ }
    </PubNubConsumer>
  </PubNubProvider>
};
```

Last updated at: 2024-06-13T07:29:12.000Z
