-2

I am following tutorial about TicTacToe in react with PubNub and when I tried to start it it says pubnub-react does not contain a default export. Any ideas why is that?

Thanks in advance!

here here

error

Dimitar
  • 1
  • 1

1 Answers1

0

Yes, that's right, pubnub-react haven't default export.

You can use it in 2 way

First

Using Destructuring Assignment

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment

import { PubNubProvider, usePubNub } from 'pubnub-react';
import React from 'react';
import PubNub from 'pubnub';
import { PubNubProvider } from 'pubnub-react';

const pubnub = new PubNub({
  publishKey: 'myPublishKey',
  subscribeKey: 'mySubscribeKey',
  uuid: 'myUniqueUUID'
});

function App() {
  return (
    <PubNubProvider client={pubnub}>
      <Chat />
    </PubNubProvider>
  );
}

Second

export all module into one using import * as <NAME>

import * as PubNubReact from 'pubnub-react';
import React from 'react';
import PubNub from 'pubnub';
import * as PubNubReact from 'pubnub-react';

const pubnub = new PubNub({
  publishKey: 'myPublishKey',
  subscribeKey: 'mySubscribeKey',
  uuid: 'myUniqueUUID'
});

function App() {
  return (
    <PubNubReact.PubNubProvider client={pubnub}>
      <Chat />
    </PubNubReact.PubNubProvider>
  );
}
Nisharg Shah
  • 16,638
  • 10
  • 62
  • 73
  • Hey, thanks for the advices, but I am not really sure about how exactly should I do it. I was following this tutorial - https://www.pubnub.com/blog/build-a-multiplayer-tic-tac-toe-game-in-react/# Any recommendations? Edit: Also added pictures of my current code :) – Dimitar Jan 04 '21 at 14:07
  • just replace that import with import { PubNubProvider, usePubNub } from 'pubnub-react'; – Nisharg Shah Jan 04 '21 at 14:33