React Hooks Cheat Sheet

In React

React Hooks is a new feature introduced in React 16.8 that allows developers to use state and other React features without writing a class. It is a way to reuse stateful logic between components, making it easier to manage complex applications.

Hooks are functions that allow you to use state and other React features in functional components. They are designed to solve common problems in React, such as managing state, handling side effects, and reusing logic between components.

The most commonly used hooks are useState, useEffect, useContext, and useReducer. useState allows you to add state to functional components, useEffect allows you to handle side effects, useContext allows you to access context in functional components, and useReducer allows you to manage complex state changes.

This cheat sheet provides a quick reference for React Hooks. It is divided into different tables based on the theme. Enjoy!

Table of Contents

State Hooks

HookDescription
useStateReturns a stateful value and a function to update it.
useReducerReturns a stateful value and a dispatch function to update it using a reducer function.

Effect Hooks

HookDescription
useEffectRuns a side effect after rendering.
useLayoutEffectRuns a side effect after rendering but before painting.
useMemoMemoizes a value to avoid unnecessary computations.
useCallbackMemoizes a function to avoid unnecessary re-renders.

Context Hooks

HookDescription
useContextReturns the current value of a context.
createContextCreates a new context.

Ref Hooks

HookDescription
useRefReturns a mutable ref object.

Reducer Hooks

HookDescription
useReducerReturns a stateful value and a dispatch function to update it using a reducer function.

Callback Hooks

HookDescription
useCallbackMemoizes a function to avoid unnecessary re-renders.

Memoization Hooks

HookDescription
useMemoMemoizes a value to avoid unnecessary computations.

Custom Hooks

HookDescription
useCustomHookA custom hook that encapsulates reusable logic.

Reference