Viral Pattani
Viral Pattani

Reputation: 21

How to use external JavaScript functions in ReactJs component?

I want to use external js like jQuery, lighterjs and other js inside my react project.

I dont know how to include js inside my project

Upvotes: 0

Views: 61

Answers (1)

Rishi1000
Rishi1000

Reputation: 344

You can iclude CDN link from jquery in your index.html in your root directory for react JS project. Then in your component you can use 'window.$'.

componentDidMount() {
    if(window.$){
        window.$( document ).ready(function() {
            console.log( "ready!" );
        });
    }
}

So, you can use any JavaScript function right away with 'window.$' prefix. Hope It will help...

Upvotes: 1

Related Questions