0

I unable to integrate javascript file in react js to jQuery functions for front end designing.

I am new to react and i have completed my components, now I want to design it using css and jQuery. For this purpose I have different files for css and jQuery. I have successfully integrated css but cannot load functions from jQuery file to react component.

I have given a path in index.html file in public folder like below:

<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>React App</title>
    <meta name="description" content="MileStone">
    <meta name="keywords" content="Portfolio">
    <title>React App</title>
</head>
<body>
    <div id="root"></div>

    <script src="./../src/js/scripts.min.js"></script>
    <script src="./../src/js/main.min.js"></script>
    <script src="./../src/js/custom.js"></script>
</body>

Any suggestions?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Muhammad Nabeel
  • 111
  • 1
  • 14
  • 1
    if you are not wrapping and external library the best advice you can collect is **do not use jQuery in React**. jQuery purpose is DOM management, but DOM is already managed by React and every thing you can do with jQuery can be done in React – Mosè Raguzzini May 03 '19 at 13:11
  • You can use jQuery or your VanillaJS files with a simple "import" statement in your react code, but as @MosèRaguzzini pointed, React and jQuery have two differents way of building webapps. jQuery -> DOM manipulating , React -> Data out the dom. – Nil May 03 '19 at 13:16
  • It is no problem to use jQuery to read the dom. Also if you want to manipulate the dom with jQuery still ok, just set the `shouldComponentUpdate` lifecycle function to false, disabling react to update the dom, so react and jquery will not conflict on which of them manipulates the dom. – gazdagergo May 03 '19 at 13:30

0 Answers0