forked from siberiacancode/reactuse
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import React from 'react'; | ||
|
||
import { useCounter } from '../useCounter/useCounter'; | ||
import { useRenderCount } from '../useRenderCount/useRenderCount'; | ||
|
||
import { useEvent } from './useEvent'; | ||
|
||
interface MemoComponentProps { | ||
onClick: () => void; | ||
} | ||
|
||
const MemoComponent = React.memo(({ onClick }: MemoComponentProps) => { | ||
const rerenderCount = useRenderCount(); | ||
|
||
return ( | ||
<> | ||
<p> | ||
Memo component rerender count: <code>{rerenderCount}</code> | ||
</p> | ||
<button type='button' onClick={onClick}> | ||
Send message | ||
</button> | ||
</> | ||
); | ||
}); | ||
|
||
const Demo = () => { | ||
const counter = useCounter(); | ||
|
||
const onClick = useEvent(() => counter.inc()); | ||
|
||
return ( | ||
<> | ||
<p> | ||
Count is: <code>{counter.count}</code> | ||
</p> | ||
<MemoComponent onClick={onClick} /> | ||
</> | ||
); | ||
}; | ||
|
||
export default Demo; |
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