简体   繁体   中英

Chrome React extension

Not able to add external JS in react app.I need to add JS after the Div tag but can't find a way.

class Main extends React.Component {
render() {
    return (
        <Frame head={[<link type="text/css" rel="stylesheet" href={chrome.runtime.getURL("/static/css/content.css")} ></link>,
         <script src="https://code.jquery.com/jquery-1.12.4.js"></script>,
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>,
 <script src="custom.js" type="text/javascript"></script>
        ]}> 
           <FrameContextConsumer>
           {
           // Callback is invoked with iframe's window and document instances
               ({document, window}) => {
                  // Render Children
                    return (

                        <div className={'my-extension'}>

                         <div>
    <div className="draggable-main">
      <h1>Test</h1>
      <h3> Group 1</h3>
      <div className="box">
        <ul className="connected-sortable draggable-left">
          <li>Test Case 1</li>
          <li>Test Case 2</li>
          <li>Test Case 3</li>
          <li>Test Case 4</li>
          <li>Test Case 5</li>
          <li>Test Case 6</li>
          <li>Test Case 7</li>
        </ul>
      </div>
      <h3>Group 2</h3>
      <div className="box">
        <ul className="connected-sortable draggable-right">
          <li>Test Case 8</li>
          <li>Test Case 9</li>
          <li>Test Case 10</li>
          <li>Test Case 11</li>
          <li>Test Case 12</li>
          <li>Test Case 13</li>
          <li>Test Case 14</li>
        </ul>
      </div>
    </div>
  </div>

</div>

                    )
                }
            }
            </FrameContextConsumer>
        </Frame>
    )
}

In this case, I need to add custom.js after div to get my functionality working. but can't add there, please suggest some ways to add external js into react component. (Note: custom.js uses jquery)

Add your code inside curly braces after your div.

<React.Fragment>
  <div>
   (your code)
  </div>
  {
   Your jquery code
  }
</React.Fragment>

Note: It is not advisable to combine two javascript frameworks it will cause performance issue.

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