简体   繁体   中英

How to add a 3rd party Jquery Library in React Functionnal component?

I want to use a 3rd library only for my homepage in a React application. The problem is: the library is developed with Jquery: www.npmjs.com/package/fullview

I need to import: Jquery, js file and css file.

so far, I haven't found any way to import this type of library into a functionnal component. Only class components.

Can I import these files directly in index.html with or i need to import them in my component with import... from "..."

Thank you !

You can add jquery CDN in your public/index.html like this:

//public/index.html
  <!DOCTYPE html>
    <html lang="en">
    <head>
       <meta charset="utf-8" />
       <link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
       <meta name="viewport" content="width=device-width, initial-scale=1" />
       <meta name="theme-color" content="#000000" />
       <meta
         name="description"
         content="Web site created using create-react-app"
       />
  <link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
  <link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
 <title>React App</title>
</head>
 <body>
    <noscript>You need to enable JavaScript to run this app.</noscript>
    <div id="root"></div>
    <script
      src="https://code.jquery.com/jquery-3.5.1.min.js"
      crossorigin="anonymous"
     ></script>
  </body>
</html>

no need to import jquery in component or something else now jquery is avalible golobally.

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