Skip to content

Instantly share code, notes, and snippets.

@AlbertProfe
Last active February 29, 2024 10:53
Show Gist options
  • Save AlbertProfe/831fbe700392b9502c77b207d1c54d78 to your computer and use it in GitHub Desktop.
Save AlbertProfe/831fbe700392b9502c77b207d1c54d78 to your computer and use it in GitHub Desktop.
render cycle
import { useState } from "react";
export default function Counter() {
const [number, setNumber] = useState(0);
let local_variable = 0;
let currentdate = new Date();
var datetime =
"Last Sync: " +
currentdate.getDay() +
"/" +
currentdate.getMonth() +
"/" +
currentdate.getFullYear() +
" @ " +
currentdate.getHours() +
":" +
currentdate.getMinutes() +
":" +
currentdate.getSeconds();
console.log("local variable", local_variable);
console.log(datetime);
local_variable++;
console.log("local variable", local_variable);
console.log("------------------------------------");
return (
<>
<h1>{number}</h1>
<button
onClick={() => {
setNumber(number + 1);
setTimeout(() => {
console.log("number render#1", number);
}, 5000);
setNumber(number + 1);
setNumber(number + 1);
setTimeout(() => {
console.log("number render#2", number);
}, 8000);
}}
>
+3
</button>
</>
);
}
@AlbertProfe
Copy link
Author

image

@AlbertProfe
Copy link
Author

2

@AlbertProfe
Copy link
Author

3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment