Member-only story
Top React Hooks — State and API
3 min readOct 1, 2020
Hooks contains our logic code in our React app.
We can create our own hooks and use hooks provided by other people.
In this article, we’ll look at some useful React hooks.
Nice Hooks
Nice Hooks is a set of hooks that does various things.
To install it, we run:
npm install nice-hooks
The useLifeCycle
hook lets us add lifecycle methods as we do with class components.
For instance, we can write:
import React from "react";
import { useLifeCycle } from "nice-hooks";export default function App() {
useLifeCycle({
didMount() {
console.log("mounted");
}, willUnmount() {
console.log("willUnmount");
}, didUpdate() {
console.log("didUpdate");
}, didMountAndWillUnmount: [
{
didMount() {
console.log("didMount");
},
willUnmount() {
console.log("willUnmount");
}
},
{
didMount() {
console.log("didMount");
},
willUnmount() {
console.log("willUnmount");
}
}
]
}); return <div />;
}