Created
March 18, 2025 20:07
-
-
Save h-agharezaei/1faae825535caf8672644998a1b79cce to your computer and use it in GitHub Desktop.
react-memo-example.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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