{"id":24211399,"url":"https://github.com/the-bugging/react-use-scripts","last_synced_at":"2026-03-05T11:33:08.806Z","repository":{"id":57347192,"uuid":"287134256","full_name":"the-bugging/react-use-scripts","owner":"the-bugging","description":"Appends script tags to the document as functions or components with ease","archived":false,"fork":false,"pushed_at":"2025-06-15T17:05:22.000Z","size":2830,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"develop","last_synced_at":"2025-11-02T00:19:03.869Z","etag":null,"topics":["helmet","hooks","react","script","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/react-use-scripts","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/the-bugging.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":["the-bugging"]}},"created_at":"2020-08-12T23:18:47.000Z","updated_at":"2025-06-15T17:05:09.000Z","dependencies_parsed_at":"2025-08-22T06:25:38.164Z","dependency_job_id":"70602a44-e4eb-4fc6-95d4-7601ab4f9185","html_url":"https://github.com/the-bugging/react-use-scripts","commit_stats":null,"previous_names":["olavoparno/react-use-scripts"],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/the-bugging/react-use-scripts","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/the-bugging%2Freact-use-scripts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/the-bugging%2Freact-use-scripts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/the-bugging%2Freact-use-scripts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/the-bugging%2Freact-use-scripts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/the-bugging","download_url":"https://codeload.github.com/the-bugging/react-use-scripts/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/the-bugging%2Freact-use-scripts/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30122177,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-05T11:11:57.947Z","status":"ssl_error","status_checked_at":"2026-03-05T11:11:29.001Z","response_time":93,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["helmet","hooks","react","script","typescript"],"created_at":"2025-01-14T02:35:11.132Z","updated_at":"2026-03-05T11:33:08.781Z","avatar_url":"https://github.com/the-bugging.png","language":"HTML","readme":"# react-use-scripts\n\n\u003e Appends script tags to the document as functions or components with ease\n\n[![NPM](https://img.shields.io/npm/v/react-use-scripts.svg)](https://www.npmjs.com/package/react-use-scripts)\n\n---\n\n| Statements                                                                                      | Branches                                                                                 | Functions                                                                                     | Lines                                                                                 |\n| ----------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------- |\n| ![Statements](https://img.shields.io/badge/statements-100%25-brightgreen.svg?style=flat\u0026logo=jest) | ![Branches](https://img.shields.io/badge/branches-85.36%25-yellow.svg?style=flat\u0026logo=jest) | ![Functions](https://img.shields.io/badge/functions-100%25-brightgreen.svg?style=flat\u0026logo=jest) | ![Lines](https://img.shields.io/badge/lines-100%25-brightgreen.svg?style=flat\u0026logo=jest) |\n\n## Table of Contents\n\n- [Install](#install)\n- [Usage](#usage)\n- [Documentation](#documentation)\n- [License](#license)\n\n---\n\n## Install\n\n```bash\nnpm install --save react-use-scripts\n```\n\n---\n\n## Usage\n\n- react-use-scripts will return a default export _useScript_ and a named export _{ ScriptLoader }_\n- Use ScriptLoader as an element in your **JSX** and add optional children and/or fallback rendering\n\n```tsx\nimport * as React from 'react';\nimport { ScriptLoader } from 'react-use-scripts';\n\nconst App = () =\u003e {\n  return (\n    \u003cScriptLoader\n      id=\"custom-script-id\"\n      src=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js\"\n      delay={500}\n      onReady={() =\u003e console.log('ready!')}\n      onError={(error) =\u003e console.log('an error has happened!', error)}\n      fallback={(error) =\u003e (\n        \u003cspan\u003eThis has errored! {JSON.stringify(error)}\u003c/span\u003e\n      )}\n    \u003e\n      \u003cspan\u003eScript has loaded succesfully!\n    \u003c/ScriptLoader\u003e\n  );\n};\n```\n\n- Append scripts to the document programmatically\n\n```tsx\nimport * as React from 'react';\nimport useScript from 'react-use-scripts';\n\nconst App = () =\u003e {\n  const [startTrigger, setStartTrigger] = React.useState(false);\n  const { ready, error } = useScript({\n    src: 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js',\n    onReady: () =\u003e console.log('ready!'),\n    onError: (error) =\u003e console.log('an error has happened!', error),\n    startTrigger,\n  });\n\n  const handleAppendScriptClick = () =\u003e {\n    setStartTrigger(true);\n  };\n\n  return (\n    \u003cdiv\u003e\n      \u003cbutton onClick={handleAppendScriptClick}\u003e\n        Click to start appending\n      \u003c/button\u003e\n      {ready \u0026\u0026 \u003ch1\u003eScript appended to the head programmatically!\u003c/h1\u003e}\n      {error \u0026\u0026 \u003ch1\u003eScript has errored! {JSON.stringify(error)}\u003c/h1\u003e}\n    \u003c/div\u003e\n  );\n};\n```\n\n---\n\n## Documentation\n\n1. `ScriptLoader`: **all props** are optional but without either _src_ or _innerText_ this will return `null`;\n\n```tsx\ninterface IScriptLoaderProps {\n  src?: string;\n  innerText?: string;\n  onReady?: () =\u003e void;\n  onError?: (error: string | Event) =\u003e void;\n  otherProps?: THTMLScriptElementProps;\n  startTrigger?: boolean;\n  id?: string;\n  appendTo?: string;\n  delay?: number;\n  children?:\n    | JSX.Element\n    | JSX.Element[]\n    | string\n    | string[]\n    | number\n    | number[];\n  fallback?: (error: string | Event) =\u003e JSX.Element;\n}\n```\n\n2. useScript\n\n```tsx\ninterface IScriptProps {\n  src?: string;\n  innerText?: string;\n  onReady?: () =\u003e void;\n  onError?: (error: string | Event) =\u003e void;\n  otherProps?: THTMLScriptElementProps;\n  startTrigger?: boolean;\n  id?: string;\n  appendTo?: string;\n  delay?: number;\n}\n```\n\n- Default Props:\n\n```tsx\n  startTrigger = true,\n  id = `react-use-script-${new Date().toISOString()}`,\n  appendTo = 'head',\n  delay = 0,\n```\n\n---\n\n## License\n\nreact-use-scripts is [MIT licensed](./LICENSE).\n\n---\n\nThis hook is created using [create-react-hook](https://github.com/hermanya/create-react-hook).\n","funding_links":["https://github.com/sponsors/the-bugging"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthe-bugging%2Freact-use-scripts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthe-bugging%2Freact-use-scripts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthe-bugging%2Freact-use-scripts/lists"}