React Hooks useState() Code

Here is the code for the video https://youtu.be/7KAb_XpWzWI
 
 
 
'use client';

import { useState } from "react";
import "./style.css";

const Home = () => {
  const [count, setCount] = useState(0);
  const [myColor, setMyColor] = useState("blue-color");

  const increment = () =>{
    setCount(count + 1);
  }

  const changeColor = () =>{
    setMyColor("red-color");
  }

  return (
    <>
      <h1 className={myColor}>useState Hook</h1>
      <h1>{count}</h1>
      <button onClick={increment}>Increment</button>
      <button onClick={changeColor}>RED</button>
    </>
  );
};

export default Home;


 

No comments:

Post a Comment

IMAGE: CODE SPLITTING - USE COMPONENTS (NEXT JS)

 CONTACTS LIST (MAIN) contacts_list.js TEXT VERSION view.js update.js TEXT VERSION