Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

setCount

import React, { useState } from "react";

const white = () => {
  return "white";
};

export default function Counter() {
  const [count, setCount] = useState(15); 
  const [currentState, setUpdateCurrentStateFunction] = useState(() => white());

  function plus() {
    setCount((prevCount) => prevCount + 1); 
  }

  function minus() {
    setCount((prevCount) => prevCount - 1);
  }

  function changeColor() {
    setUpdateCurrentStateFunction("yellow");
  }

  return (
    <div>
      <button className="plus" onClick={plus}>
        +
      </button>
      <p>{count}</p>
      <p>{currentState}</p>
      <button className="minus" onClick={minus}>
        -
      </button>
      <button onClick={changeColor}>CHANGE COLOR</button>
    </div>
  );
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: How to go back to previous route after authentication in nextjs 
Javascript :: metodos de arrays javascript 
Javascript :: how to convert html string to jsx element 
Javascript :: random color by EventListener click 
Javascript :: how to get the first element in an array in javascript 
Javascript :: zustand stores manage loading state 
Javascript :: js proxy track nested object 
Javascript :: js cyclic motion based on cosine 
Javascript :: copy multi cell value from one sheet to another using google app script 
Javascript :: angularjs smooth scroll css 
Javascript :: if the params of usequery updated 
Javascript :: react-social-login-buttons 
Javascript :: Pointing Subdomain To A Next.js Page On Vercel 
Javascript :: javascript Why is this function working on second click only 
Javascript :: js num to str 
Javascript :: angularjs Both outer and inner divs have ng-click and when I click on the inner div, both ng-clicks execute. How to prevent that 
Javascript :: angularjs New Entry Not reflacting in table after inserting New record in CRUD angular app 
Javascript :: Porting Promise Chaining from AngularJs to VueJs 
Javascript :: Calculating state happens to late 
Javascript :: How to make this code cleaner? react native 
Javascript :: the given sign-in provider is disabled for this firebase project 
Javascript :: how to hide prerendered page button in nextjs 
Javascript :: filter a object array tree javascript 
Javascript :: Simple Mustache.js 
Javascript :: ENOENT electron 
Javascript :: inspect vuex store 
Javascript :: force browser reload page from server javascript 
Javascript :: electron write to csv 
Javascript :: Accessing Function Declared Outside Constructor But Inside Class 
Javascript :: javascript hide div 
ADD CONTENT
Topic
Content
Source link
Name
1+3 =