-3

I have recently switched to React inorder to achieve single page application

Previously I had 8 html files and 8 js files which were linked by script tag

<script  src="pathHere"> </script>

Now as I switched to React. Now the html pages are replaced by components with extension .js

How can I link some components(which have html content) with js (which contain js in jquery format) I tried to add component of js file in my jsx


import FirstJsFile from "../ApiCalls/FirstJsFile";
const Display = () =>{
    return (
        <div>
     // jsx written here
    <FistJsFile/> // This is  the js file which  conatins js in form of jquery
        </div>
    )
}

export default Display;

Then the js file contains this

const FristJsFile = () =>{
    return (
        <>{
            $(function(){
                console.log("Jquery getting loaded")
                }
        </>
    )
}

export default FirstJsFile
2
  • 3
    At the top-level of the React application there's still an HTML page. You can add <script> tags to that page. However, you probably shouldn't be mixing React and jQuery. Not unless you really know what you're doing. If you're just throwing together plugins for functionality, it's probably going to fail in a variety of ways as both jQuery and React do very different things with the DOM. Commented Apr 5, 2022 at 19:31
  • 3
    Double down on what @David says.... JQuery and React have pretty orthogonal approaches to UI management that don't generally mix well at all. IMHO you should ditch jquery if using React. Commented Apr 5, 2022 at 19:37

1 Answer 1

0

I recommend using react-state instead of jquery.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.