Skip to content

Instantly share code, notes, and snippets.

@qkreltms
Created June 7, 2021 10:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qkreltms/6749f6054c33c58ca0c969f092271c32 to your computer and use it in GitHub Desktop.
Save qkreltms/6749f6054c33c58ca0c969f092271c32 to your computer and use it in GitHub Desktop.
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
@qkreltms
Copy link
Author

emoticon_tip_gif_example

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