Skip to content

Instantly share code, notes, and snippets.

@h-agharezaei
Created March 24, 2025 10:33
Show Gist options
  • Save h-agharezaei/bb4a0607427439a24332db2104fcd30d to your computer and use it in GitHub Desktop.
Save h-agharezaei/bb4a0607427439a24332db2104fcd30d to your computer and use it in GitHub Desktop.
import { useState, useEffect } from "react";
function Component() {
const [count, setCount] = useState(0);
const [text, setText] = useState("");
useEffect(() => {
console.log("Count updated:", count);
}, [count, text]); // مشکل: این اثر هر بار که count یا text تغییر کند اجرا می‌شود
return (
<div>
<p>Count: {count}</p>
<button onClick={() => setCount(count + 1)}>افزایش</button>
<input value={text} onChange={(e) => setText(e.target.value)} />
</div>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment