Bacancy Bacancy
      • About Company
      • Resources

      About Company

      About Us Leadership Team Customer Reviews Awards & Recognition
      Infrastructure Our Locations Partnership

      Resources

      Press Room Blog Insights
      We are great place to work certified™

      Building and Sustaining High-Trust, High-Performance Culture

      Get Quote
    • Engagement Models

      Hiring Software Developers becomes easier with just a few clicks.

      Software Development Outsourcing

      End-to-end delivery of custom solutions aligned to your roadmap.

      Staff Augmentation

      Scale your in-house team with pre-vetted specialists on demand.

      Dedicated Teams

      Get dedicated engineers who work exclusively on your project.

      • Enterprise Services
      • IT Services
      • Data Analytics
      • Cloud Services
      • AI & ML
      • Platforms

      Enterprise Services

      Digital Transformation Business Process Automation Digital Product Engineering Enterprise App Development Custom Software Development

      IT Services

      Legacy App Modernization DevOps & SRE Full Stack Development AI Testing & QA Automation

      Data Analytics

      Data Visualization & Reporting Data Engineering & Pipelines Data Science & Predictive Analytics Business Intelligence

      Cloud Services

      Cloud Strategy & Consulting Cloud Migration & Modernization Multi Cloud Management

      AI & ML

      AI Development Agentic AI Generative AI Computer Vision Machine Learning & MLOps

      Platforms

      Salesforce SAP ServiceNow Microsoft Dynamics Snowflake
      High-quality, Cost-effective IT Outsourcing

      Schedule a free discovery session to explore your needs and find tailored solutions with no obligation.

      explore all services
    • Industries
      Healthcare Fintech Real Estate
      Logistics Education Retail & Ecommerce
      Let's Grow Together! Get Quote
      • Front End
      • Backend
      • Mobile
      • Databases
      • DevOps & Infra
      • AI & Data Stack
      • Vibe Coding

      Front End

      React.js Next.js Angular Vue.js TypeScript
      Your Very Own UI/UX Architects

      Experience smooth navigation and user-friendly designs with our front-end expertise.

      Hire Frontend Developer

      Backend

      Node.js Python Java Spring Boot Laravel .NET C# Golang FastAPI
      Server Solutions To Change Power Dynamics

      Transform your data into digital experiences with optimized coding standards.

      Hire Backend Developer

      Mobile

      iOS Android Flutter React Native
      Innovating Mobile-Friendly App Solutions

      Create dynamic mobile apps that make your brand stand out from the crowd.

      Hire Mobile App Developer

      Databases

      PostgreSQL MongoDB MySQL Redis Supabase
      Dedicated Talent With Skilled Approach

      Bring your digital visions to life with a hired resource at your convenience.

      Hire Dedicated Developer

      DevOps & Infra

      AWS Azure Google Cloud Docker Kubernetes Terraform
      Redefining Scalable Digital Infrastructures

      Make your data accessible worldwide at will, and leave the stress behind.

      Get Quote

      AI & Data Stack

      OpenAI LangChain LlamaIndex Apache Spark Airflow Tableau PowerBI Databricks
      Guiding Decisions With Data-Driven Insights

      Transition from your gut calls to actionable insights with our rich Data Science expertise.

      Get Quote

      Vibe Coding

      Base44 Claude Code Cursor Lovable Github Copilot
      Your AI-Native Development Team

      Skip the boilerplate. Our vibe coding experts use AI-first tools to go from prompt to product, fast.

      Hire Vibe Coding Developer
  • Case Studies
  • Contact Us
Find a Developer book a 30 min call
      • About Us
      • Leadership Team
      • Customer Reviews
      • Awards & Recognition
      • Infrastructure
      • Our Locations
      • Partnership
      • Press Room
      • Blog
      • Insights
      • Digital Transformation
      • Business Process Automation
      • Digital Product Engineering
      • Enterprise App Development
      • Custom Software Development
      • Legacy App Modernization
      • DevOps & SRE
      • Full Stack Development
      • AI Testing & QA Automation
      • Data Visualization & Reporting
      • Data Engineering & Pipelines
      • Data Science & Predictive Analytics
      • Business Intelligence
      • Cloud Strategy & Consulting
      • Cloud Migration & Modernization
      • Multi Cloud Management
      • AI Development
      • Agentic AI
      • Generative AI
      • Computer Vision
      • Machine Learning & MLOps
      • Salesforce
      • SAP
      • ServiceNow
      • Microsoft Dynamics
      • Snowflake
    • Healthcare
    • Fintech
    • Real Estate
    • Logistics
    • Education
    • Retail & Ecommerce
      • React.js
      • Next.js
      • Angular
      • Vue.js
      • TypeScript
      • Hire Frontend Developer
      • Node.js
      • Python
      • Java
      • Spring Boot
      • Laravel
      • .NET
      • C#
      • Golang
      • FastAPI
      • Hire Backend Developer
      • iOS
      • Android
      • Flutter
      • React Native
      • Hire Mobile App Developer
      • PostgreSQL
      • MongoDB
      • MySQL
      • Redis
      • Supabase
      • Hire Dedicated Developer
      • AWS
      • Azure
      • Google Cloud
      • Docker
      • Kubernetes
      • Terraform
      • Get Quote
      • OpenAI
      • LangChain
      • LlamaIndex
      • Apache Spark
      • Airflow
      • Tableau
      • PowerBI
      • Databricks
      • Get Quote
      • Base44
      • Claude Code
      • Cursor
      • Lovable
      • Github Copilot
      • Hire Vibe Coding Developer
  • Case Studies
  • Contact Us
  • Find a Developer
  • book a 30 min call
react hooks

A Comprehensive Guideline to UseState In React Hooks

Vivek Patel
Vivek Patel Full Stack Developer
Last Updated on November 14, 2024 | Written By: Vivek Patel

Quick Summary: The blog comprises of the journey for the beginners; who have started using
React useState. Let’s have an in-detail look at useState in React hooks. It will help to get your hands on useState in React theoretically and practically.

1. Overview: What does React hooks mean?
2. Why React hooks?
3. How to work with useState hook?
4. What does useState in React return us?
5. Conclusion

Overview: What Does React Hooks mean?

React Hooks are built-in functions that allow us to hook into React state and lifecycle from the functional(stateless) component.

From this, we can assume that using hooks makes it possible to manipulate our functional component’s state. There’s no need to convert our functional component to a class component for handling the React state. Oops, there’s one more thing that should be kept in mind while working with React Hooks: Hooks can’t be used inside the class component.

Your component should be a functional component if you want to access hooks.

React Hooks not only allows us to manipulate and work with states but also helps us in avoiding various lifecycle methods: componentDidMount, componentDidUpdate, and componentWillUnmount. Alternatively, we can use useEffect, React built-in hooks, for the same. Okay, this can be said as an overview of React Hooks.

Why React to Hooks?

We all are well aware of the benefits of React provided by its functional component.

Moreover, it’s difficult to use stateful logic amongst components. If you’re familiar with, react, then ,you might be knowing about render props and high-order component, which tries to solve the problem of attaching reusable behavior to a component. But, while using this, you have to organize your components. And this will make your code more difficult to understand. If you observe this in your React DevTools, you’ll find a “wrapper hell” of components. With React Hooks, you can reuse the stateful logic without manipulating your component hierarchy.

Another perk of using React Hooks can be said that it simplifies your code and component structure. Those who had worked with React would be familiar with lifecycle and of course the bugs and inconsistencies due to it. React Hooks allow you to split one component into different small functional components. Because of this division, the bugs caused due to unwanted interference of unrelated logic amongst various lifecycle will be taken care of.

React Hooks which are mainly in use:

  • useState: Helps in manipulating state within the functional component.
  • useEffect: Helps in working with lifecycle inside the functional component.
  • useContext: Acquires the value returned from React.createContext and returns the current context value, which is given by the nearest context provider for that context.

Among the various React hooks, useState will be the concern of this blog, so the main focus will be on useState in React functional component. Okay, let’s dive into it.

How to work with useState hook?

function useStateExample() {
  // Declaring useState hook.
  const [weight, setWeight] = useState(45);
  console.log(weight);  // 45
  setWeight(50);
  console.log(weight);  // 50
 // ..
}

The line const [weight, setWeight] = useState(45); declares a state variable named weight and a function setWeight which allows you to update the preceding state variable, here weight.

And there must be a question about the initial value of the state variable! While using the useState hook, what value would be assigned to the state before calling the function?

Look at the snippet, and you’ll find your answer. Yes! The value enclosed in curved brackets used while declaring the state variable, is denoted as the initial value of the state variable. Here the initial value, that is the first value before updating the state using the function, of weight is 45.

Looking for exceptional React development services for your project?
Get in touch with the best React development company to implement your goals and build best-in-class apps.

So, are we clear? Okay. Good! Let’s proceed.

We have 45 as our initial value. After that, when we want to update the value of weight, we will use setWeight(50)- any desired value can be passed. Easy and less complicated! isn’t it?

It’s not even mandatory that the state variable has to be an object. Although it can be, there’s no compulsion.

—————————————————————————————————————————————–
There’s one thing you should follow while working with useState hook:
Declare your state variables and function related to it at the top of your functional component. Don’t call hooks inside loops, conditions or nested functions.

—————————————————————————————————————————————–

What does useState in React return us?

Now, heading towards what does useState in React returns us? It returns a pair of values: the current state variable and a function that updates that particular variable.

Declaring multiple state variables :
function MoreExamplesOfHooks() {
  const [weight, setWeight] = useState(45);
  const [vegetable, setVegetable] = useState(‘Tomato’);
  const [name, setName] = useState([{ firstName: 'Neha' }]);
  //.. 
}

Basic example using useState in React.

import React, { useState } from "react";

export default function HooksExampleUsingState() {
  const [buttonValue, setButtonValue] = useState("Click me!");

  return (
    < button onClick={() => setButtonValue("Thanks for clicking!")} >
      {buttonValue}
    < /button >
  );
}

Here, state variable name buttonValue and function which update buttonValue is setButtonValue. As we learned before, the value within the curved bracket is said to be the initial value. Thus, Click me! is displayed on the button. As soon as the button is clicked, setButtonValue is called. Remember, the button already had its initial value. But, now the function call will update it. Thus, the value displayed on the button will be Thanks for clicking!.

Since there is no updation in the value of the state variable of React usestate hook, no changes will further appear.

React will maintain this state variable between re-renders.

If required, you can also call the function as a regular function rather than using an inline arrow function.

import React, { useState } from "react";

export default function Button() {
  const [buttonValue, setButtonValue] = useState("Click me!");

  function handleClick() {
    return setButtonValue("Thanks for clicking!");
  }

  return < button onClick={handleClick} >{buttonValue}< /button >;
}

Conclusion:

React Hooks are built-in functions that allows you to hook into React state and lifecycle in functional components.

With React Hooks, you can reuse the stateful logic without manipulating your component hierarchy and get rid of “wrapper hell.” Hooks in React makes your code look simple and clean.

const [weight, setWeight] = useState(45)
weight: state variable
setWeight: a function that manipulates the value assigned to weight
useState(45): useState hook which	initializes the value of weight with 45.

useState hook returns a pair of values: the current state variable and a function that updates that particular variable.

Now, get your hands-on React Hooks and start exploring a new version of React.js. If you are looking for ReactJS experts who can help you get the job done, then hire ReactJS developers from us today to leverage their top-of-the-line expertise.


Expand Your Digital Horizons With Us.

Start a new project or take an existing one to the next level. Get in touch to start small, scale-up, and go Agile.


Or
E-mail us : solutions@bacancy.com

Your Success Is Guaranteed !

Related Articles

Vivek Patel

February 20, 2026

React JS

React Server Components: Guide & Best Practices 2026

By : Vivek Patel

Read More
Dipal Bhavsar

September 23, 2025

React JS

How to Get Started with React Flow? Step-by-Step Tutorial to Build Interactive Workflows

By : Dipal Bhavsar

React Flow is a React library that builds interactive workflows and automation tools. It offers features like drag-and-drop nodes, customizable...

Read More
Darshan Joshi

August 25, 2025

Web Development

Top Web Development Trends Not To Miss in 2026

By : Darshan Joshi

Web development is constantly undergoing transformative changes. Whether we talk about AI-driven coding tools, serverless architectures, or sustainable web practices,...

Read More

Offices and Development Centers

Bacancy Ahmedabad Ahmedabad

15-16, Times Corporate Park, Thaltej, Ahmedabad, 380059

Bacancy Gandhinagar Gandhinagar

422-A, 4th Floor, Pragya Tower Road 11, Block 15, Zone 1, SEZ-PA Gandhinagar, 382355

Bacancy Hyderabad Hyderabad

Awfis, Level 1, N Heights, Plot No 38, Phase 2, Hitech City Hyderabad, 500081

Bacancy Mumbai Mumbai

18th Floor, Cyberone, opp. CIDCO Exhibition Centre, Sector 30, Vashi, Navi Mumbai, 400703

Bacancy Pune Pune

2nd FloorMarisoft-1, Marigold IT Park, Pune - 411014

Bacancy Bengaluru Bengaluru

Raheja Towers, 26/27, Mahatma Gandhi Rd, East Wing, Craig Park Layout, Ashok Nagar, Bengaluru, 560001

Global Presence

Bacancy New Jersey New Jersey

33 South Wood Ave, Suite 600, Iselin NJ 08830

Bacancy California California

535 Mission St 14th floor, San Francisco, CA 94105

Bacancy Massachusetts Massachusetts

501 Boylston St, Boston, MA 02116

Bacancy Florida Florida

4995 NW, 72nd Avenue, Suite 307, Miami, FL, 33166

Bacancy London London

90 York Wy, London N1 9AG, United Kingdom

Bacancy Ontario Ontario

71 Dawes Road, Brampton, On L6X 5N9, Toronto

Bacancy Australia Australia

351A Hampstead Rd, Northfield SA 5085

Bacancy UAE UAE

One Central 8th and 9th Floor - Trade Centre - Trade Centre 2 - Dubai - United Arab Emirates

Bacancy Sweden Sweden

Junkergatan 4, 126 53 Hagersten

Get in Touch

Great Place to Work

Get in Touch

cal-icon

Looking for expert advice?

Schedule a Expert Call


  • Brochure
  • Quality Assurance
  • Resources
  • Tutorials
  • Customer Reviews
  • Privacy Policy
  • FAQs
  • Press Room
  • Contact Us
  • Sitemap
  • Employee

bacancy google review 4.6
bacancy google review
bacancy clutch review 4.8
bacancy clutch review
bacancy goodfirms review 4.8
bacancy goodfirms review
iso
  • Bacancy Behance
  • Bacancy Pinterest

Copyright © 2026 BACANCY SERVICES PRIVATE LIMITED All rights reserved.