简体   繁体   中英

Import external script into React component

I am converting a template into react components for my site. However, the template are mostly in jquery. The external javascripts are not binding well with my component and I have to bind the function with componentDidMount() .

componentDidMount(){
  $(".b-upper-title").slabText({
      // Don't slabtext the headers if the viewport is under 380px
      "viewportBreakpoint":380
  });
}

However, slabText() is not working since it is dependent on <script src="styles/plugins/slabText/js/jquery.slabtext.min.js"></script> . I need to import this script into the component in order to call the function. Any idea how to perform the task?

尝试看看这个库react-async-script-loader

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