简体   繁体   中英

How to integrate skylink in react project?

I am using Skylink for video calling and I want to use in a react project. I know how to use it with Vanilla JavaScript as their demo project is at codepen But when I try to use it with react I am getting some errors. Here is how I tried:

  1. Installed the package from npm using Yarn.
  2. Imported the package import SkyLink from 'skylinkjs'
  3. Then called the function constructor const skylink = new SkyLink(); But I get the following error:

Uncaught TypeError: __WEBPACK_IMPORTED_MODULE_3_skylinkjs___default.a is not a constructor

If I try to import like this:

import {SkyLink} from 'skylinkjs'; const skylink = new SkyLink();

then the error is

Uncaught TypeError: __WEBPACK_IMPORTED_MODULE_3_skylinkjs__.SkyLink is not a constructor

and If I try to import all from the module and then call the function costructor:

import * as SkyLink from 'skylinkjs'; const skylink = new SkyLink();

the error will be this Uncaught TypeError: __WEBPACK_IMPORTED_MODULE_3_skylinkjs__ is not a constructor

Can you please tell me what am I doing wrong?

You have a typo. Either of the following would work.

import { Skylink } from 'skylinkjs';
const skylink = new Skylink();

or

import skylinkjs from 'skylinkjs';
const skylink = new skylinkjs.Skylink();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM