---
title: "Discussion on \"Hooks in React\" | Hashnode"
description: "Discussion on \"Hooks in React\". Today we'll learn about the widely used hooks in React. First, let me tell you the need for hooks. As we all know React has functional and class components. Previously, the functional components were only used to render the data but didn't consist of..."
url: "https://hashnode.com/posts/hooks-in-react/60941cbda7a3827bb64ce418"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Hooks in React](https://deepansh946.hashnode.dev/hooks-in-react?utm_source=hashnode&utm_medium=feed)

Today we'll learn about the widely used hooks in React. First, let me tell you the need for hooks. As we all know React has functional and class components. Previously, the functional components were only used to render the data but didn't consist of...

May 6, 2021 · 4 min read · deepansh946.hashnode.dev  
Updated May 10, 2021  
Read the article

-   [#reactjs](https://hashnode.com/tag/reactjs)
-   [#javascript](https://hashnode.com/tag/javascript)

## Written by

[Deepansh Bhargava](https://hashnode.com/@deepansh)

@deepansh · Guna, India

  
[View profile](https://hashnode.com/@deepansh)

Software Developer @ HST Solar

Hey, 👋 I am a full stack engineer who is well versed with microservices architecture and UI/UX concepts. I can build highly scalable web apps that can scale to lakhs of users and can write modular code for better results. I am always eager to learn new technologies and methodologies.

## Responses 3

Markdown supported · ⌘↵ to post

[Mauricio Neftali Melendez Macias](https://hashnode.com/@Mauricio09)

[May 7, 2021](https://hashnode.com/posts/hooks-in-react/60941cbda7a3827bb64ce418/comment/6095d00221068818a5c60995)

Buena explicación, creo que solo me falta comprender mejor el hook useReducer👍

[Uddesh Jain](https://hashnode.com/@uddeshjain)

[May 7, 2021](https://hashnode.com/posts/hooks-in-react/60941cbda7a3827bb64ce418/comment/6094d413a7a3827bb64cedaf)

Well explained. Now useReducer hook make sense to me.

[Phillip Ninan](https://hashnode.com/@phillip_ninan)

[May 7, 2021](https://hashnode.com/posts/hooks-in-react/60941cbda7a3827bb64ce418/comment/6094b932d1bbc47b91a678da)

Very good read! I am pretty new to react. I was a little confused on the first couple of lines.

```
const [number, setNumber] = useState(0);
```

Were `number` and `setNumber` defined someplace?

Why do you pass `0` to `useState`? Then you pass `true` to it here?

```
const [isEven, toggleEven] = useState(true);
```

I look forward to reading more!

[Deepansh Bhargava](https://hashnode.com/@deepansh)

[May 7, 2021](https://hashnode.com/posts/hooks-in-react/60941cbda7a3827bb64ce418/comment/6094b932d1bbc47b91a678da#reply-6094d3abd1bbc47b91a67ae0)

Thanks for pointing this out.

1.  So the `useState` hook returns an array consisting of two elements, and we can name these variables as per our need.
    
2.  The 0 passed in the `useState` is the initial value of the state variable. I wanted to set the value of `number` as 0 and as it is even so I have set the value of `isEven` as `true`.
    

[Phillip Ninan](https://hashnode.com/@phillip_ninan)

[May 7, 2021](https://hashnode.com/posts/hooks-in-react/60941cbda7a3827bb64ce418/comment/6094b932d1bbc47b91a678da#reply-6095463ff7929f0c6e37ca11)

[Deepansh Bhargava](https://hashnode.com/@deepansh)

Ah, that makes sense! Thank you for clearing that up for me Deepansh!
