0.1.0 • Published 3 years ago

react-hooks-constructor v0.1.0

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

Constructor in React Hooks

react-hooks-constructor is a React Hooks library used to implement a constructor for functional React components. Constructors are used to run once and before everything else.

Installation ⚙️

Use the package manager npm to install react-hooks-constructor.

npm install react-hooks-constructor

Usage 🛠️

// ...
import useConstructor from "react-hooks-constructor";

function App() {
  useConstructor(() => {
    console.log(
      "This only happens ONCE and it happens BEFORE the initial render."
    );
  });
  const [counter, setCounter] = useState(0);

  return (
    <>
      <div>Counter: {counter}</div>
      <div style={{ marginTop: 20 }}>
        <button onClick={() => setCounter(counter + 1)}>Increment</button>
      </div>
    </>
  );
};

Contributing 💭

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License 📝

MIT