Home > Software engineering >  I want to change the value of 5 when Refresh button is clicked with useState
I want to change the value of 5 when Refresh button is clicked with useState

Time:07-09

i know i did somthing wrong, but idk what XD,, help please

CodePudding user response:

You are using setrefClick incorrectly, it should be like this:

function refreshClick() {
   // This will put 8 into refClick
   setrefClick(8);
}

CodePudding user response:

You are doing states wrong.

You are doing it just fine.

In order to initialize state you should follow this syntax

const [state, stateUpdate] = useState(initialValue);

Upon observing your code, you can potentially change your state initialization to a proper way like this.

const [pageTitle, setPageTitle] = useState("Customers");
const [customersCount, setCustomersCount] = useState(5);

And modify the customersCount like this:

setCustomersCount(5);

Edit:

This is just a suggestion, however you can change the customerCount using

setrefClick(8);
  • Related