DEV Community

Akhilesh Gupta
Akhilesh Gupta

Posted on • Edited on

How to useState in React?

hey!

As a newbie, when I started react JS, I don't know where to start today I'm learning how use useState hook in react.

newbie code.

import React, { useState } from "react";
import "./App.css";

function App() {

  const [activated, setActivated] = useState(false);
  return (

    <div className="App">
      <h2>React useState Hook</h2>
      <p>I am {activated ? "on" : "off"}.</p>
      <button type="button"
        className="main-button"
        onClick={() => setActivated(activated ? false : true)}> 
       {activated ? "Deactivate Me !" : "Activate Me !"}!</button>
    </div>

  );

}

export default App;
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

AWS GenAI LIVE image

Real challenges. Real solutions. Real talk.

From technical discussions to philosophical debates, AWS and AWS Partners examine the impact and evolution of gen AI.

Learn more

👋 Kindness is contagious

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

Okay