{"id":13902831,"url":"https://github.com/princefishthrower/react-use-please-stay","last_synced_at":"2025-07-18T00:32:17.625Z","repository":{"id":46578503,"uuid":"354525266","full_name":"princefishthrower/react-use-please-stay","owner":"princefishthrower","description":"A React hook that animates the document title and/or favicon when focus from the page is lost.","archived":false,"fork":false,"pushed_at":"2021-10-09T08:52:45.000Z","size":2229,"stargazers_count":152,"open_issues_count":7,"forks_count":7,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-11-07T01:07:43.818Z","etag":null,"topics":["favicon","hacktoberfest","hook","hooks","react","react-hooks","title-animation"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/princefishthrower.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-04-04T11:22:47.000Z","updated_at":"2024-10-12T16:36:25.000Z","dependencies_parsed_at":"2022-07-20T06:17:04.944Z","dependency_job_id":null,"html_url":"https://github.com/princefishthrower/react-use-please-stay","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/princefishthrower%2Freact-use-please-stay","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/princefishthrower%2Freact-use-please-stay/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/princefishthrower%2Freact-use-please-stay/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/princefishthrower%2Freact-use-please-stay/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/princefishthrower","download_url":"https://codeload.github.com/princefishthrower/react-use-please-stay/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226320635,"owners_count":17606334,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["favicon","hacktoberfest","hook","hooks","react","react-hooks","title-animation"],"created_at":"2024-08-06T22:01:27.064Z","updated_at":"2024-11-25T11:30:37.216Z","avatar_url":"https://github.com/princefishthrower.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# react-use-please-stay  \n[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/princefishthrower/react-use-please-stay/blob/master/LICENSE) [![npm version](https://img.shields.io/npm/v/react-use-please-stay.svg?style=flat)](https://www.npmjs.com/package/react-use-please-stay) ![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg) \n\n🎃 ![](https://img.shields.io/github/hacktoberfest/2021/princefishthrower/react-use-please-stay) 🎃\n\n![react-use-please-stay at work](example.gif)\n\nA React hook that animates the document title and/or favicon when focus from the page is lost. (Or jump down to [the options](#options) to see how you can set it up to _always_ animate! 😉)\n\n# Interactive Demo\n\n[A fully interactive demo is here.](https://princefishthrower.github.io/react-use-please-stay)\n\n# Getting Started\n\nInstall and save this package as a dependency:\n\n```bash\nnpm install --save react-use-please-stay\n```\n\nImport the hook with:\n\n```tsx\nimport { usePleaseStay } from 'react-use-please-stay';\n```\n\nUse it within your functional component! (It has return type of `void`, so you can just call it):\n\n```tsx\nusePleaseStay({ titles: [\"Don't go!\", 'We have React hooks!'] });\n```\n\n\u003ca name=\"options\"\u003e\u003c/a\u003e\n# Options\n\nOptions for the hook are passed via an object of [type `UsePleaseStayOptions` (click me!)](./src/types/UsePleaseStayOptions.ts).\n\n# Usage\n\nMinimal usage in a component, passing the single required option `titles`:\n\n```tsx\nfunction App() {\n  usePleaseStay({ titles: [\"Don't go!\", 'We have React hooks!'] });\n  return (\n    \u003c\u003e\n      \u003ch1\u003eusePleaseStay\u003c/h1\u003e\n      \u003cp\u003e\n        An example of the usePleaseStay hook. Leaving this browser tab open, navigate\n        or open another tab and watch the magic happen!\n      \u003c/p\u003e\n    \u003c/\u003e\n  );\n}\n\nexport default App;\n```\n\nLoop through multiple messages:\n\n```tsx\nusePleaseStay({\n  titles: [\"Don't go!\", 'We have React hooks!', \"We're sad!\", 'Come back!'],\n});\n```\n\nPass a single message and set the `animationType` option to `AnimationType.CASCADE` to cascade the letters (default is `AnimationType.LOOP`):\n\n```tsx\nusePleaseStay({\n  titles: [\"React App\"],\n  animationType: AnimationType.CASCADE\n});\n```\n\nOptional - specify a slower interval time in milliseconds (default is `1000`):\n\n```tsx\nusePleaseStay({\n  titles: [\"Don't go!\", 'We have React hooks!', \"We're sad!\", 'Come back!'],\n  interval: 3000,\n});\n```\n\nOptional - add in one or more favicon URIs to loop through each time the title changes (default is `[]`):\n\n```tsx\nusePleaseStay({\n  titles: [\"Don't go!\", 'We have React hooks!', \"We're sad!\", 'Come back!'],\n  interval: 3000,\n  faviconURIs: ['https://redux.js.org/img/favicon/favicon.ico'],\n});\n```\n\nOptional - have the animation always run with the `alwaysRunAnimations` (default is `false`):\n\n```tsx\nusePleaseStay({\n  titles: [\"Don't go!\", 'We have React hooks!', \"We're sad!\", 'Come back!'],\n  interval: 3000,\n  faviconURIs: ['https://redux.js.org/img/favicon/favicon.ico'],\n  alwaysRunAnimations: true,\n});\n```\n\nThat's about it for all possible configurations. \n\n# Pitfalls\n\n**Since this hook interacts with `document.title` directly it should only be called only ***once*** in your app**, for example in a layout or `App` component - otherwise the title animation will not be smooth and things could get... _strange_.\n\n# Known Issues\n\nIn some frameworks like GatsbyJS, the `document.title` is injected some time after the hook mounts and thus the default title set when returning to the page is sometimes wrong. \n\n_This causes incorrect behavior only in development environments. There are no known issues in production builds._\n\n# JQuery Implementation\n\nFor those interested, the only JQuery implementation I could find was in this [GitHub gist](https://gist.github.com/sonnm/fcaaf616e62cc46e8756599306f4e1ad#file-jquery-pleasestay-js). I'm not sure if there is an official package out there for either a vanilla JavaScript or jQuery version; I couldn't find either.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprincefishthrower%2Freact-use-please-stay","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprincefishthrower%2Freact-use-please-stay","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprincefishthrower%2Freact-use-please-stay/lists"}