question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to override onScriptLoaded function?

See original GitHub issue

Hi. I’m trying to set a function different from noop (the default) to be triggered but I can’t seem to be able to do it. I’ve tried changing defaultProps for the wrapped component but that didn’t work.

Ideally, I wanted to be able to define the function when I call the scriptLoader function, maybe like this: (the name of my wrapper component is Metrics)

export default scriptLoader(
  [
    'http://path.to.my.script.net/script.js'
  ],'', function(){ console.log('onScriptLoader was called...'); })(Metrics);

Is this (or something like this) possible?

Thank you

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

10reactions
vsc-githubcommented, Jul 7, 2017

@leozdgao I agree with @oyeanuj . The usage of onScriptLoaded is unclear, it is not described in the docs as well. I want to mount a component after my script loads. How should I use onScriptLoaded in such a case?

0reactions
jpt1971commented, Mar 21, 2018

Please could someone give an example of how to use the onScriptLoaded function. else going to have to find a different library to use, which sucks 😦

I know the author wrote:

This is how onScriptLoader works: const MockedComponent = AsyncScriptLoader.apply(null, deps)(TestComponent)

<MockedComponent onScriptLoaded={onScriptLoaded} />

but, maybe I am benig dense, I don’t under stand how that would relate to the code example in the docco:

import React, { Component } from ‘react’ import scriptLoader from ‘react-async-script-loader’   class Editor extends Component {   …     componentWillReceiveProps ({ isScriptLoaded, isScriptLoadSucceed }) {     if (isScriptLoaded && !this.props.isScriptLoaded) { // load finished        if (isScriptLoadSucceed) {         this.initEditor()       }       else this.props.onError()     }   }     componentDidMount () {     const { isScriptLoaded, isScriptLoadSucceed } = this.props     if (isScriptLoaded && isScriptLoadSucceed) {       this.initEditor()     }   }     … }   export default scriptLoader(   [     ‘https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js’,     ‘https://cdnjs.cloudflare.com/ajax/libs/marked/0.3.5/marked.min.js’   ],   ‘/assets/bootstrap-markdown.js’ )(Editor)

??

Read more comments on GitHub >

github_iconTop Results From Across the Web

Call javascript function after script is loaded - Stack Overflow
I want to call a js function e.g. loadedContent(); once the above script adds dynamic html. Can someone help me how I can...
Read more >
How to override a JavaScript function ? - GeeksforGeeks
In this article, we are given an HTML document and the task is to override the function, either a predefined function or a...
Read more >
Callbacks — NUKE Python Developer's Guide v11.3v2 ...
The onScriptLoad knob is visible in the Project Settings > Python tab. ... However, you can change this behavior by using the function...
Read more >
jQuery getScript Alternatives | Kevin Chisholm - Blog
The onScriptLoad function takes care of using the console to let us know that the script has loaded and to show us the...
Read more >
override a Javascript function inside another function?
override a Javascript function inside another function? - Javascript Function. Javascript examples for Function:Function Nest.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found