DEV Community

`Nazir Abubakar
`Nazir Abubakar

Posted on

3 1

What is useState

what is usestate ???

Hooks

To understand usestate, you first need an understanding on what hooks are.

Hooks are the new feature introduced in the React 16.8 version. It allows you to use state and other React features without writing a class or stateless component. Hooks are the functions which "hook into" React state and lifecycle features from function components.

They are like blocks of code(in case of useState, a line of code) that saves us a lot of time when building projects.

UseState

const [state, setState] = useState(0)

this is an instance of the usestate hook, it accepts a parameter, and return two properties, the first property "state" is immutable you can't change it directly, but in the most likely case of you wanting to change the value of that state you, then invoke the second property "setState".

The setState is a method that accepts parameter and reassigns those value to state. and we can dynamically change the value of state without writing a bunch of codes.

p.s. I just learnt what usestates was about and decided to share.

if you have questions feel free to ask.

Image of Datadog

Master Mobile Monitoring for iOS Apps

Monitor your app’s health with real-time insights into crash-free rates, start times, and more. Optimize performance and prevent user churn by addressing critical issues like app hangs, and ANRs. Learn how to keep your iOS app running smoothly across all devices by downloading this eBook.

Get The eBook

Top comments (1)

Collapse
 
schinta2 profile image
siva sandeep chintamaneni

While you can attempt to modify the state value directly, it doesn't produce the intended effect.
beta.reactjs.org/ - new docs provide a great mental model about state and other fundamentals.

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay