React Guide
React Guide
React Hooks
Black Friday Sale @Courses React Course React Tutorial React Exercise React Basic Concepts Rea
Last Updated : 17 Oct, 2024
React Hooks are used to hook into the features like state and lifecycle
methods of React Component. Generally, Hooks are special functions
that provide access to state in the React Application.
Hooks were introduced in the 16.8 version of React. Hooks give access
to states for functional components while creating a React application. It
allows you to use state and other React features without writing a class.
Table of Content
What are React Hooks?
When to use React Hooks
Types of React Hooks
Benefits of using Hooks
Why the need for ReactJs Hooks?
Rules for using Hooks
Using Hooks in React
Difference Between Hooks and Class Components
Important things to remember while using hooks
State Hooks
Context Hooks
Ref Hooks
Effect Hooks
Performance Hooks
Resource Hooks
Other Hooks
State Hooks stores and provide access to the information. To add state
in Components we use:
Refs creates the variable containing the information not used for
rendering e.g. DOM nodes.
4. Effect Hooks:
Effects connect the components and make it sync with the system. It
includes changes in browser DOM, networks and other libraries.
Performace hooks are a way to skip the unnecessary work and optimise
the rendering preformance.
use: used to read the value of resources e.g., context and promises.
Apart from these Built-in React hooks we can also create Custom
Hooks in React.
You can see a Complete list of React Hooks in ReactJS Hooks Complete
Reference.
JavaScript
1 // Filename - index.js
2
3 import React, { useState } from "react";
import ReactDOM from "react-dom/client";
5 function App() {
6 const [click, setClick] = useState(0);
7
8 // Using array destructuring here
9 // to assign initial value 0
10 // to click and a reference to the function
11 // that updates click to setClick
12 return (
13 <div>
14 <p>You clicked {click} times</p>
15 <button onClick={() => setClick(click +
1)}>
16 Click me
17 </button>
18 </div>
19 );
20 }
21
22 const root = ReactDOM.createRoot(
23 document.getElementById("root")
24 );
25 root.render(
26 <React.StrictMode>
27 <App />
28 </React.StrictMode>
29 );
Output:
Spread across
Code Structure methods, can be Smaller, focused functions
complex
Error
Supported Not currently supported
Boundaries
R Raju… 36
React Hooks
Similar Reads
When is it best to use custom hooks instead of built-in React hooks?
Custom hooks in React are useful when you want to extract and reuse
stateful logic across multiple components. While built-in React hooks lik…
2 min read
What are React Hooks, and why were they added to React?
React Hooks are a way to add functionality to functional components in
React. Before Hooks, functional components were more limited compare…
2 min read
Languages DSA
Python Data Structures
Java Algorithms
C++ DSA for Beginners
PHP Basic DSA Problems
GoLang DSA Roadmap
SQL DSA Interview Questions
R Language Competitive Programming
Android Tutorial
DSA/Placements Development/Testing
DSA - Self Paced Course JavaScript Full Course
DSA in JavaScript - Self Paced Course React JS Course
DSA in Python - Self Paced React Native Course
C Programming Course Online - Learn C with Data Structures Django Web Development Course
Complete Interview Preparation Complete Bootstrap Course
Master Competitive Programming Full Stack Development - [LIVE]
Core CS Subject for Interview Preparation JAVA Backend Development - [LIVE]
Mastering System Design: LLD to HLD Complete Software Testing Course [LIVE]
Tech Interview 101 - From DSA to System Design [LIVE] Android Mastery with Kotlin [LIVE]
DSA to Development [HYBRID]
Placement Preparation Crash Course [LIVE]
Clouds/Devops GATE
DevOps Engineering GATE CS & IT Test Series - 2025
AWS Solutions Architect Certification GATE DA Test Series 2025
Salesforce Certified Administrator Course GATE CS & IT Course - 2025
GATE DA Course 2025