usePubNub Hook

The usePubNub hook lets you interact with PubNub in function components.

Hooks are a new feature added in React 16.8 that allow you to use React features without writing a class. For a general overview of hooks, refer to the React documentation.

Example

import React from 'react';
import { usePubNub } from '../../src/index';

const PubNubTime = () => {
const PubNubClient = usePubNub();

return (
<div>
const [time, setTime] = useState("Loading");

PubNubClient.time((status, response) => setTime(response.timetoken));

{time}
</div>
);
show all 18 lines
Last updated on
On this page