Skip to content
This repository was archived by the owner on Feb 18, 2023. It is now read-only.

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

 
 
 

Contributors