react-load-script icon indicating copy to clipboard operation
react-load-script copied to clipboard

How to use?

Open Tzikas opened this issue 6 years ago • 6 comments

I'm a little confused about the example: I have

handleScriptCreate() {
  this.setState({ scriptLoaded: false })
}
 
handleScriptError() {
  this.setState({ scriptError: true })
}
 
handleScriptLoad() {
  console.log(this)
  this.setState({ scriptLoaded: true })
  $('body').click(function(){
		alert('up')
   })
}
 
render() {
   return(

    <Script
      url="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"
      onCreate={this.handleScriptCreate.bind(this)}
      onError={this.handleScriptError.bind(this)}
      onLoad={this.handleScriptLoad.bind(this)}
    />
  )
}

and I'm getting a error '$' is not defined . jQuery in component did mount doesn't work either. What am I doing wrong?

Tzikas avatar Dec 30 '17 18:12 Tzikas

Script Loaded is true in the state.

Tzikas avatar Dec 30 '17 18:12 Tzikas

Any progress on this?

njho avatar Mar 21 '18 20:03 njho

Have you tried window.$('body').click(function(){alert('up');})? If you're using webpack or anything, it won't have a reference to $ since it's not defined in your webpack config.

XianHain avatar Apr 13 '18 20:04 XianHain

im having his same issue, how can i access the script once loaded?

jmdelgadoh avatar Apr 12 '19 23:04 jmdelgadoh

im having his same issue, how can i access the script once loaded?

if you use wbpack it's not a problem react-load-script you need to add npm module jquery and add to your component import * as $ from 'jquery'; (window as any).jQuery = $; (window as any).$ = $; that's all

https://github.com/webpack/webpack/issues/4258#issuecomment-401820798

mail4andrey avatar Apr 15 '19 06:04 mail4andrey

Same issue here.

ArtixZ avatar Apr 03 '20 18:04 ArtixZ