0.1.1 • Published 4 years ago
@monolithed/use-script-hook v0.1.1
@monolithed/use-script-hook
A React hook to dynamically load scripts
Installation
Install with npm or Yarn:
npm:
npm install @monolithed/use-script-hook --saveYarn:
yarn add @monolithed/use-script-hookBasic 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 testPublishing
npm publish --access public --verboseLicense
MIT
Contributing
Feel free to submit a pull request if you find any bugs. Please make sure all commits are properly documented.
