Skip to content
This repository has been archived by the owner on Feb 18, 2023. It is now read-only.
/ unhook Public archive

Unscoped hooks

License

MIT, MIT licenses found

Licenses found

MIT
LICENSE
MIT
license.md
Notifications You must be signed in to change notification settings

dy/unhook

Repository files navigation

unhook Build Status experimental

Unleash react/preact hooks from components, make them available in regular javascript without hooks limitations.

NPM

import { useEffect, useState } from 'unhook'

function tick() {
  let [count, setCount] = useState(0)

  useEffect(() => {
    let id = setInterval(() => {
      setCount(count => count + 1)

      // NOTE: function must be triggered manually
      tick()
    }, 1000)
    return () => clearInterval(id)
  }, [])
}

Internally, unhook uses error.stack, which is non-standard, but well supported by all browsers/engines for a long time.

For production, it is possible to statically compile source to avoid using error.stack. (pending feature...)

See also

  • enhook - turn a function into hooks-enabled function.
  • any-hooks - obtain any installed hooks.
  • unihooks - collection of universal hooks

HK

About

Unscoped hooks

Topics

Resources

License

MIT, MIT licenses found

Licenses found

MIT
LICENSE
MIT
license.md

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published