Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • React Tutorial
  • React Exercise
  • React Basic Concepts
  • React Components
  • React Props
  • React Hooks
  • React Router
  • React Advanced
  • React Examples
  • React Interview Questions
  • React Projects
  • Next.js Tutorial
  • React Bootstrap
  • React Material UI
  • React Ant Design
  • React Desktop
  • React Rebass
  • React Blueprint
  • JavaScript
  • Web Technology
Open In App
Next Article:
ReactJS Hooks Reference
Next article icon

ReactJS Hooks Reference

Last Updated : 17 Mar, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

React hooks are functions that allow you to use state and other React features in functional components. Hooks were introduced in React 16.8, enabling developers to manage state and lifecycle features without needing class components. They simplify the development process and make it easier to write reusable and cleaner code.

Below is the basic representation of the React JS Hooks useState.

CSS
/* Write CSS Here */ .App {     display: flex;     flex-direction: column;     justify-content: center;     align-items: center; }  body {     background-color: antiquewhite; }  .App>h2 {     text-align: center; }  .App>button {     width: 8rem;     font-size: larger;     padding: 2vmax auto;     height: 1.8rem;     color: white;     background-color: rgb(34, 34, 33);     border-radius: 10px; }  button:hover {     background-color: rgb(80, 80, 78); } 
JavaScript
import React, { useState } from 'react'; import './App.css'  const App = () => {     const [num, setNum] = useState(0);     const handleClick = () => {         setNum(num + 1);     };      return (         <div className="App">             <h2> {num}</h2>             <button onClick={handleClick}>                 Add one             </button>         </div>     ); };  export default App; 
  • The useState hook is used to create a num state, initialized to 0, and a setNum function to update it when the button is clicked.
  • The handleClick function increments num by 1 each time the button is clicked, updating the displayed value in the <h2> tag.

Output

onClickevent2GIF

Why Use React Hooks?

  • Simplifies Code: Hooks provide a simpler and cleaner way to write components by using functions instead of classes.
  • State and Side Effects: Hooks allow you to use state (useState) and side effects (useEffect) in functional components.
  • Reusability: Hooks make it easier to share logic across components by creating custom hooks.
  • Readability: Functional components with hooks tend to be more concise and easier to read than class components.

Different Hooks in React

  • useState: useState is used to add state to functional components.
  • useEffect: useEffect is used to perform side effects (like fetching data or subscribing to services) in functional components.
  • useContext: useContext allows you to access the value of a context in functional components.
  • useReducer: useReducer is an alternative to useState for more complex state logic.
  • useRef: useRef returns a mutable ref object which can be used to reference DOM elements or store mutable values.
  • useMemo: useMemo is used to memoize values or computations to prevent expensive calculations on every render.
  • useCallback: useCallback is used to memoize functions so that they are not recreated on every render.
  • useLayoutEffect: Similar to useEffect, but it runs synchronously after all DOM mutations, allowing you to perform operations on the layout.
  • useImperativeHandle: useImperativeHandle customizes the instance value that is exposed when using ref in functional components.

Advantages of Using Hooks

  • Cleaner Code: Hooks make code simpler and easier to read by allowing state and effects to be used directly in functional components.
  • Better Reusability: Custom hooks allow the reuse of logic across different components.
  • No this keyword: Hooks eliminate the need for the this keyword found in class components, reducing complexity and mistakes.
  • More Functionality in Functional Components: Previously, only class components could use lifecycle methods and state. Now, with hooks, even functional components can manage state, side effects, and other features.

React JS Hooks Reference

  • useState Hook
  • useEffect Hook
  • useRef Hook
  • useMemo Hook
  • useContext Hook
  • useReducer Hook
  • useHistory Hook
  • useNavigate Hook
  • useParams Hook
  • useLayoutEffect Hook
  • useImperativeHandle Hook
  • useDebugValue Hook
  • useUndoState Hook
  • useSelect Hook
  • useCallback Hook
  • useTransition Hook
  • useId Hook
  • useInsertionEffect Hook
  • ReactJS Custom Hooks
  • useLocalStorage Custom Hook
  • useForm Custom Hook
  • useTimeout Custom Hook
  • useOrientation Custom Hook
  • useInterval Custom Hook

Next Article
ReactJS Hooks Reference

K

kartik
Improve
Article Tags :
  • Web Technologies
  • ReactJS
  • React-Hooks

Similar Reads

    ReactJS useReducer Hook
    The useReducer hook is an alternative to the useState hook that is preferred when you have complex state logic. It is useful when the state transitions depend on previous state values or when you need to handle actions that can update the state differently.Syntaxconst [state, dispatch] = useReducer(
    5 min read
    ReactJS useEffect Hook
    The useEffect hook is one of the most commonly used hooks in ReactJS used to handle side effects in functional components. Before hooks, these kinds of tasks were only possible in class components through lifecycle methods like componentDidMount, componentDidUpdate, and componentWillUnmount.What is
    4 min read
    Resource Hooks in React
    In React, components often need to access external resources such as data from promises or context information for styling. Managing these resources within the component state could lead to unnecessary complexity and performance overhead. React provides a simple solution with the 'use' hook to overc
    3 min read
    Ref Hooks in React
    Ref Hooks provide a way to access and interact with the DOM (Document Object Model) nodes directly within functional components. Before hooks, refs were primarily used in class components. However, with Ref Hooks, functional components can also take advantage of this capability, enhancing flexibilit
    4 min read
    React-Router Hooks
    React-Router is a popular React library that is heavily used for client-side routing and offers single-page routing. It provides various Component APIs( like Route, Link, Switch, etc.) that you can use in your React application to render different components based on the URL pathnames on a single pa
    11 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences