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
1import React from 'react';
2import { usePubNub } from '../../src/index';
3
4const PubNubTime = () => {
5 const PubNubClient = usePubNub();
6
7 return (
8 <div>
9 const [time, setTime] = useState("Loading");
10
11 PubNubClient.time((status, response) => setTime(response.timetoken));
12
13 {time}
14 </div>
15 );
show all 18 lines