0

First of all I'm still a newbie in web development. Okay, now to the question. I have these imports:

import $ from 'jquery'; 
window.jQuery = $;
window.$ = $;
global.jQuery = $;
import './assets/js/waves';

How do I properly import an external javascript to reactjs if my external javascript requires jquery?

Because based on what these guys have said:

reactjs, bootstrap and npm import - jQuery is not defined

Are ES6 module imports hoisted?

my imports will be hoisted, which results in my external "./assets/js/waves" js causing an error.

Uncaught ReferenceError: $ is not defined?

Thanks in advance!

Community
  • 1
  • 1
Macho Gwapito
  • 149
  • 2
  • 12

1 Answers1

0
import * as jQuery from 'jquery';

Then you have a reference of jQuery and you may do with it what you like, for instance:

window.$ = jQuery;
ideaboxer
  • 3,863
  • 8
  • 43
  • 62
  • thanks @ideaboxer but somehow it still did not work. question, where do you think should I put this? In a component or in the parent (index)? – Macho Gwapito Jul 11 '17 at 02:47
  • It must have something to do with the content of the *waves.js* file. Could you post (part of) its content so that we can analyze it? – ideaboxer Jul 11 '17 at 16:44