0.1.1 • Published 3 years ago

@monolithed/use-script-hook v0.1.1

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

@monolithed/use-script-hook

Build Status License

A React hook to dynamically load scripts

Installation

Install with npm or Yarn:

npm:

npm install @monolithed/use-script-hook --save

Yarn:

yarn add @monolithed/use-script-hook

Basic usage

import React, {FunctionComponent} from 'react';
import {useScript} from '@monolithed/use-script-hook';

type Props = {
    src: string;
};

const LazyService: FunctionComponent<Props> = ({src}): JSX.Element => {
    const {loaded, failed, script} = useScript({src});
   
    return <div>script {script.src} is {loaded}</div>;
};

Attributes

async (default is true) src (required)

const {loaded, failed} = useScript({src, async});

Options

verbose — a boolean indicator of sending states to the console

const {loaded, failed} = useScript({src}, {verbose: true});

Tests

npm test

Publishing

npm publish --access public --verbose

License

MIT

Contributing

Feel free to submit a pull request if you find any bugs. Please make sure all commits are properly documented.