File tree Expand file tree Collapse file tree 2 files changed +11
-7
lines changed Expand file tree Collapse file tree 2 files changed +11
-7
lines changed Original file line number Diff line number Diff line change 11import { createContext , useContextSelector } from '@rc-component/context' ;
22import React from 'react' ;
3+ import useRenderTimes from './useRenderTimes' ;
34
45const CountContext = createContext < {
56 cnt1 : number ;
67 cnt2 : number ;
78} > ( ) ;
89
9- const useRenderTimes = ( ) => {
10- const renderRef = React . useRef ( 0 ) ;
11- renderRef . current += 1 ;
12-
13- return renderRef . current ;
14- } ;
15-
1610const MyConsumer = React . memo ( ( { name } : { name : any } ) => {
1711 const value = useContextSelector ( CountContext , name ) ;
1812 const renderTimes = useRenderTimes ( ) ;
Original file line number Diff line number Diff line change 1+ import React from 'react' ;
2+
3+ const useRenderTimes = ( ) => {
4+ const renderRef = React . useRef ( 0 ) ;
5+ renderRef . current += 1 ;
6+
7+ return renderRef . current ;
8+ } ;
9+
10+ export default useRenderTimes ;
You can’t perform that action at this time.
0 commit comments