@solid-primitives/script-loader
Creates a primitive to load scripts dynamically, either for external services or jsonp requests
Installation
npm install @solid-primitives/script-loader
# or
yarn add @solid-primitives/script-loader
How to use it
const [script: HTMLScriptElement, remove: () => void] = createScriptLoader({
src: string | Accessor<string>,
type?: string,
onload?: () => void,
onerror?: () => void
});
createScriptLoader({
src: 'https://www.google.com/recaptcha/enterprise.js?render=my_token'
onload: async () => {
await grecaptcha.enterprise.ready();
const token = await grecaptcha.enterprise.execute('my_token', {action: 'login'});
}
});
const pinterestEmbedScript = '!function(a,b,c){var d,e,f;d="PIN_"+~~((new Date).getTime()/864e5),...';
createScriptLoader({
src: pinterestEmbedScript,
onload: () => window?.PinUtils?.build()
});
Demo
TODO
Changelog
See CHANGELOG.md