Skip to content

Instantly share code, notes, and snippets.

@h-agharezaei
Created March 18, 2025 20:07
Show Gist options
  • Select an option

  • Save h-agharezaei/1faae825535caf8672644998a1b79cce to your computer and use it in GitHub Desktop.

Select an option

Save h-agharezaei/1faae825535caf8672644998a1b79cce to your computer and use it in GitHub Desktop.
react-memo-example.tsx
import React, { useState, memo } from "react";
const ExpensiveComponent = memo(({ count }: { count: number }) => {
console.log("Rendered!");
return <div>Count: {count}</div>;
});
export default function App() {
const [count, setCount] = useState(0);
const [text, setText] = useState("");
return (
<div>
<ExpensiveComponent count={count} />
<button onClick={() => setCount(count + 1)}>Increase Count</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