How to useState in React?

akhilh2o

Akhilesh Gupta

Posted on October 10, 2020

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
💖 💪 🙅 🚩
akhilh2o
Akhilesh Gupta

Posted on October 10, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

How to useState in React?
react How to useState in React?

October 10, 2020