Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use? #20

Open
Tzikas opened this issue Dec 30, 2017 · 6 comments
Open

How to use? #20

Tzikas opened this issue Dec 30, 2017 · 6 comments

Comments

@Tzikas
Copy link

Tzikas commented Dec 30, 2017

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
Copy link
Author

Tzikas commented Dec 30, 2017

Script Loaded is true in the state.

@njho
Copy link

njho commented Mar 21, 2018

Any progress on this?

@XianHain
Copy link

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.

@jmdelgadoh
Copy link

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

@mail4andrey
Copy link

mail4andrey commented Apr 15, 2019

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

webpack/webpack#4258 (comment)

@ArtixZ
Copy link

ArtixZ commented Apr 3, 2020

Same issue here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants