Skip to content

How to use? #20

Open
Open

Description

@Tzikas

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?

Activity

  1. Tzikas commented on Dec 30, 2017

    @Tzikas
    Author

    Script Loaded is true in the state.

  2. njho commented on Mar 21, 2018

    @njho

    Any progress on this?

  3. XianHain commented on Apr 13, 2018

    @XianHain

    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.

  4. jmdelgadoh commented on Apr 12, 2019

    @jmdelgadoh

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

  5. mail4andrey commented on Apr 15, 2019

    @mail4andrey

    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)

  6. ArtixZ commented on Apr 3, 2020

    @ArtixZ

    Same issue here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions