@@ -6,8 +6,6 @@ export type CompareProps<T extends React.ComponentType<any>> = (
66 nextProps : Readonly < React . ComponentProps < T > > ,
77) => boolean ;
88
9- type ImmutableProps < T extends React . ComponentType < any > > = Omit < React . ComponentProps < T > , 'ref' > ;
10-
119/**
1210 * Create Immutable pair for `makeImmutable` and `responseImmutable`.
1311 */
@@ -34,24 +32,24 @@ export default function createImmutable() {
3432 function makeImmutable < T extends React . ComponentType < any > > (
3533 Component : T ,
3634 shouldTriggerRender ?: CompareProps < T > ,
37- ) : React . ComponentType < React . ComponentProps < T > > {
35+ ) : T {
3836 const refAble = supportRef ( Component ) ;
3937
40- const ImmutableComponent = ( props : ImmutableProps < T > , ref : React . Ref < any > ) => {
38+ const ImmutableComponent : React . ForwardRefRenderFunction < any , any > = ( props , ref ) => {
4139 const refProps = refAble ? { ref } : { } ;
4240 const renderTimesRef = React . useRef ( 0 ) ;
4341 const prevProps = React . useRef ( props ) ;
4442
4543 // If parent has the context, we do not wrap it
4644 const mark = useImmutableMark ( ) ;
4745 if ( mark !== null ) {
48- return < Component { ...( props as any ) } { ...refProps } /> ;
46+ return < Component { ...props } { ...refProps } /> ;
4947 }
5048
5149 if (
5250 // Always trigger re-render if `shouldTriggerRender` is not provided
5351 ! shouldTriggerRender ||
54- shouldTriggerRender ( prevProps . current as any , props as any )
52+ shouldTriggerRender ( prevProps . current , props )
5553 ) {
5654 renderTimesRef . current += 1 ;
5755 }
@@ -60,7 +58,7 @@ export default function createImmutable() {
6058
6159 return (
6260 < ImmutableContext . Provider value = { renderTimesRef . current } >
63- < Component { ...( props as any ) } { ...refProps } />
61+ < Component { ...props } { ...refProps } />
6462 </ ImmutableContext . Provider >
6563 ) ;
6664 } ;
@@ -70,8 +68,8 @@ export default function createImmutable() {
7068 }
7169
7270 return refAble
73- ? ( React . forwardRef ( ImmutableComponent ) as React . ComponentType < React . ComponentProps < T > > )
74- : ( ImmutableComponent as unknown as React . ComponentType < React . ComponentProps < T > > ) ;
71+ ? ( React . forwardRef ( ImmutableComponent ) as unknown as T )
72+ : ( ImmutableComponent as T ) ;
7573 }
7674
7775 /**
@@ -81,13 +79,13 @@ export default function createImmutable() {
8179 function responseImmutable < T extends React . ComponentType < any > > (
8280 Component : T ,
8381 propsAreEqual ?: CompareProps < T > ,
84- ) : React . ComponentType < React . ComponentProps < T > > {
82+ ) : T {
8583 const refAble = supportRef ( Component ) ;
8684
87- const ImmutableComponent = ( props : ImmutableProps < T > , ref : React . Ref < any > ) => {
85+ const ImmutableComponent : React . ForwardRefRenderFunction < any , any > = ( props , ref ) => {
8886 const refProps = refAble ? { ref } : { } ;
8987 useImmutableMark ( ) ;
90- return < Component { ...( props as any ) } { ...refProps } /> ;
88+ return < Component { ...props } { ...refProps } /> ;
9189 } ;
9290
9391 if ( process . env . NODE_ENV !== 'production' ) {
@@ -96,13 +94,10 @@ export default function createImmutable() {
9694 } )`;
9795 }
9896
99- return refAble
100- ? ( React . memo ( React . forwardRef ( ImmutableComponent ) , propsAreEqual ) as React . ComponentType <
101- React . ComponentProps < T >
102- > )
103- : ( React . memo ( ImmutableComponent , propsAreEqual ) as unknown as React . ComponentType <
104- React . ComponentProps < T >
105- > ) ;
97+ return React . memo (
98+ refAble ? React . forwardRef ( ImmutableComponent ) : ImmutableComponent ,
99+ propsAreEqual ,
100+ ) as unknown as T ;
106101 }
107102
108103 return {
0 commit comments