This package has been deprecated

Author message:

Experimental.

unhook

1.0.0 • Public • Published

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
  • remorph - react-based morphdom

HK

Package Sidebar

Install

npm i unhook

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

6.95 kB

Total Files

9

Last publish

Collaborators

  • dy