Member-only story
Top React Hooks — Forms and Forward Refs
3 min readOct 13, 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.
react-use
The react-use library is a big library with many handy hooks.
useMethods
The useMethods
hook is a simpler useReducer
hook implementation.
It lets us cache states so it’s useful for using complex computations.
For instance, we can write:
import React from "react";
import { useMethods } from "react-use";const initialState = {
count: 0
};function countMethods(state) {
return {
reset() {
return initialState;
},
increment() {
return { ...state, count: state.count + 1 };
},
decrement() {
return { ...state, count: state.count - 1 };
}
};
}export default function App() {
const [state, methods] = useMethods(countMethods, initialState); return (
<>
<p>{state.count}</p>
<button onClick={methods.increment}>increment</button>
<button onClick={methods.decrement}>decrement</button>
<button…