0.0.1 • Published 3 years ago

solid-use-script v0.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

solid-use-script

Solid hook to dynamically load an external script.

npm i -S solid-use-script

Usage

import { Switch, Match } from 'solid-js';
import { useScript } from 'solid-use-script';

function App() {
  const [loading, error] = useScript('https://some.api');

  return (
    <Switch fallback={<ApiProvider>...</ApiProvider>}>
      <Match when={loading()}>Loading API...</Match>
      <Match when={error()}>Failed to load API: {error().message}</Match>
    </Switch>
  );
}

Attributes

useScript('https://some.api', { crossorigin: 'anonymous' });