Created
June 7, 2021 10:43
-
-
Save qkreltms/6749f6054c33c58ca0c969f092271c32 to your computer and use it in GitHub Desktop.
This file contains 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
const CountButton = React.memo(function CountButton({ onClick, count }: any) { | |
return <button onClick={onClick}>{count}</button>; | |
}); | |
function DualCounter() { | |
const [count1, setCount1] = React.useState(0) | |
const [count2, setCount2] = React.useState(0) | |
const increment1 = React.useCallback(()=>setCount1(c => c + 1),[]) | |
const increment2 = React.useCallback(()=>setCount2(c => c + 1),[]) | |
const h=[] | |
for(let i=0;i<100;i++){ | |
h.push(i) | |
} | |
return ( | |
<> | |
<CountButton count={count1} onClick={increment1} /> | |
{h.map(()=>( | |
<CountButton count={count2} onClick={increment2} /> | |
))} | |
</> | |
) | |
} | |
export default DualCounter |
Author
qkreltms
commented
Nov 23, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment