✕
Forbes India Leader Recognition
e.preventDefault(); // Prevent form submission input.blur(); // remove focus input.value = ""; // optional: clear the input

Hooks in React

Hooks in React

Featured Image

What is a Hook?

Hooks are the functions that let you work with the state and lifecycle components of React by using function components. Hooks is a concept which allows us to use React inside a function, we don’t need to define classes for it.

Introduction to Hooks

It’s always stressful to reuse a stateful logic between components. Can use state and other React without defining a class. Also without changing the hierarchy of the component we can reuse the stateful logic.

We often have to take care of components that begin simply but grow into an unmanageable stateful logic and side effects. Each lifecycle method may contain a mixture of unrelated logic. For instance, a component might perform API calling to fetch some data which can be done in the lifecycle method componentDidMount and componentDidUpdate.

An equivalent componentDidMount method can additionally have some unrelated logic that calls event listeners, Mutually related code that changes or works together gets split into different parts, but completely unrelated code finishes up combined during a single method. This might lead to inconsistency or even introduce bugs.

To overcome this, using Hooks we can separate one component into smaller functions supporting what pieces are related rather than forcing a split supported lifecycle method.

Rules

  • Should only call the hooks at the Top most level.
  • Should only call the hooks from the React Function not from class.

Effect

useEffect, ability to perform side effects inside a functional component. It most likely works as the lifecycle methods “componentDidMount”, “componentDidUpdate”, and “componentWillUnmount” in React classes, but unified into one API.

State

After the introduction of ES6 we have no “this” in a functional component, so we can’t use this.state. Instead, we can call the useState Hook inside our functional component for the using the state. It will only take a single argument that is the initial state.

Related Posts

Latest Posts

  • All Posts
  • AI Powered Knowledge
  • ai/ml
  • CEO India Magazine
  • CMMI level 5 Certification
  • e-learning
  • Fintech
  • gaming
  • Generative AI
  • healthcare
  • manufacturing
  • News
  • OTT
  • Portfolio
  • supply chain
  • travel and hospitality
  • Tudip's AI Hackathon
  • Voxlearn Enterprises
    •   Back
    • Android
    • iOS
    • Java
    • PHP
    • MEAN
    • Ruby
    • DotNet
    • IoT
    • Cloud
    • Testing
    • Roku
    • CMS
    • Python
Artificial Intelligence in Healthcare

Artificial Intelligence in Healthcare

September 23, 2026

Explore how artificial intelligence in healthcare is transforming clinical decision-making, and patient care .

Read More
AI in Manufacturing: Machine Intelligence  Meets Industrial Innovation

AI in Manufacturing: Machine Intelligence Meets Industrial Innovation

September 23, 2026

Explore how AI is transforming manufacturing through predictive maintenance, intelligent quality control, data-driven operations.

Read More
Artificial Intelligence in Manufacturing: Enabling Intelligent, Flexible and Cost-Effective Production Through AI

Artificial Intelligence in Manufacturing: Enabling Intelligent, Flexible and Cost-Effective Production Through AI

September 23, 2026

Discover how AI is transforming manufacturing through intelligent automation.

Read More

India

Plot No. 11/2, Phase 3, Hinjewadi Rajiv Gandhi Infotech Park, Pune, India – 411057.
info@tudip.com
+91-96-8990-0537

United States

1999 S. Bascom Ave Suite 700, Campbell CA. 95008, USA.
info@tudip.com
+1-408-216-8162

Canada

64 Caracas Road North York, Toronto Ontario M2K 1B1, Canada.
info@tudip.com

Mexico

Calle Amado Nervo #785 Interior B Colonia Ladron De Guevara 44600 Guadalajara, Jalisco, Mexico.
info@tudip.com

Singapore

77 High Street, #10-12B High Street Plaza, Singapore 179433.
info@tudip.com

Colombia

Cra. 9 # 113-53 Of. 1405 Bogotá D.C., Colombia.
info@tudip.com

UAE

Tudip Information Technologies L.L.C Office No 109, ABU HAIL BUILDING 13, Abu Hail, Dubai, UAE.
info@tudip.com

Nigeria

22 Kumasi Crescent, Wuse 2, Abuja, Nigeria.
info@tudip.com