Skip to content

useScript ​

Category
Browser

Hook that manages a script with onLoad, onError, and removeOnUnmount functionalities

typescript
import { useScript } from '@siberiacancode/reactuse';

Usage ​

typescript
const status = useScript('https://example.com/script.js');

Demo ​

Api ​

Parameters

NameTypeDefaultNote
srcstring-The source of the script
options?UseScriptOptions-The options of the script extends from attributes script tag
options.removeOnUnmount?booleantrueWhether to remove the script on unmount
options.async?booleantrueWhether to load the script asynchronously

Contributors ​

Source • Demo