react-async-script-loader icon indicating copy to clipboard operation
react-async-script-loader copied to clipboard

How is onScriptLoaded intended to be used?

Open petervijeh opened this issue 7 years ago • 1 comments

Not clear how this method is used, are there any examples anywhere?

petervijeh avatar Jan 11 '19 20:01 petervijeh

@petervijeh As I understand it, it's meant to be passed down as a prop by parent components as necessary.

import MyAsyncComponent from 'components/MyAsyncComponent';

const onScriptLoaded = () => {
   // Run code that is dependant on the script being loaded.
  let script = window.loadedScript;
  script.run('foo', bar);
};

return () => <MyAsyncComponent onScriptLoaded={onScriptLoaded} />

AndrewLowther avatar Apr 04 '19 07:04 AndrewLowther