DEV Community

Sarvesh Upadhyay
Sarvesh Upadhyay

Posted on

An Introduction To React’s Context API

In this post, you will learn how to use React’s Context API which allows you to manage global application states in your React apps without resorting to props drilling.

  1. That is basically what a React hook is. It allows us to use state, refs and other React features in our functional components.

THE useState (HOOK)
The useState hook allows us to use state in our functional components. A useState hook takes the initial value of our state as the only argument, and it returns an array of two elements. The first element is our state variable and the second element is a function in which we can use the update the value of the state variable.

Let’s take a look at the following example.
**import React, {useState} from "react";

function SampleComponent(){
const [count, setCount] = useState(0);
}
**

Top comments (2)

Collapse
 
rohitmaurya1 profile image
Rohit Maurya

i support this post in my problem solving good....

Collapse
 
sarveshupadhyay21 profile image
Sarvesh Upadhyay

Thanks bhai