usehook

0.5.2 • Public • Published

useHook

dependencies size (gzip size module formats: umd, cjs, and es

npm package MIT License React PRs welcome

Just use the hooks. This library aims to provide a possibility to use fancy React hooks in yur plain old components. Yes, even in classes. It does so, by providing a render prop which you can pass your hook to.

Usage

See example folder. Or enjoy a codesandbox!

import React, { useState } from 'react';
 
import UseHook from 'usehook';
 
class Hooked extends React.Component {
  render() {
    return (
      <UseHook hook={[useState, 0]}>
        {([number, setNumber]) => (
          <div>
            <span>Number: {number}</span>
            <button onClick={() => setNumber(number + 1)}>+1</button>
          </div>
        )}
      </UseHook>
    );
}

Contributors

Thanks goes to these people (emoji key):


Christoph Benjamin Weber

💻 📖 💡

This project follows the all-contributors specification. Contributions of any kind welcome!

LICENSE

MIT

Package Sidebar

Install

npm i usehook

Weekly Downloads

8

Version

0.5.2

License

MIT

Unpacked Size

10.9 kB

Total Files

11

Last publish

Collaborators

  • kriswep