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.


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

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

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

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

show all 18 lines
Last updated on
On this page