Skip to content

Prevent Repeat Calls of usePleaseStay  #1

@princefishthrower

Description

@princefishthrower

As the README states, one pitfall of this hook is that it should only be called once across an entire codebase - otherwise, it will create multiple timeout interactions on the document.title and will ruin the effect, not to mention add extra load to the browser. I'm looking for a code-based way to prevent this from occurring - perhaps by assigning an ID from the setInterval command:

https://developer.mozilla.org/en-US/docs/Web/API/setInterval

Logic should be something like as follows:

  • I would expect a setInterval ID to be saved in state (or I think a ref would work)
  • if the usePleaseStay() hook was called a second time and it was found this ID was already set, the developer should:
    • in development mode, see a new Error() be thrown
    • in production mode, prevent further execution of the second calling of the hook (simply return from the function)

Metadata

Metadata

Labels

hacktoberfestIssue designated for Hacktoberfest

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions