SanichKotikov / solid-use-script

Solid hook to dynamically load an external script.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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' });

About

Solid hook to dynamically load an external script.

License:MIT License


Languages

Language:TypeScript 100.0%