2.0.0 • Published 4 years ago

classify-hook v2.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

ClassifyHook license version PRs

Use any react hook in class components

Install

$ yarn add classify-hook

or

$ npm i classify-hook

Example Usage (counter)

import React, { useState } from "react";
import Hook from "classify-hook";

class App extends React.Component {
  constructor(props) {
    super(props);
    this.state = {};
  }

  render() {
    return (
      <>
        <Hook
          hook={() => useState(0)}
          onUpdate={([counter, setCounter]) =>
            this.setState({ counter, setCounter })
          }
        />
        <div style={{ textAlign: "center", padding: 80 }}>
          <h3>{this.state.counter}</h3>
          <button onClick={() => this.state.setCounter(this.state.counter + 1)}>
            Click
          </button>
        </div>
      </>
    );
  }
}

export default App;
2.0.0

4 years ago

1.0.0

4 years ago