import { copyStaticProperties } from './instance' ; import { Moize , Moized as MoizedFunction , Moizeable , Options } from './types' ; import { setName } from './utils' ; const REACT_ELEMENT_TYPE = typeof Symbol === 'function' && Symbol . for ? Symbol . for ( 'react.element' ) : 0xeac7 ; private description param moizer param fn param options returns export function createMoizedComponent < OriginalFn extends Moizeable > ( moizer , fn , options ) { /**
     * This is a hack override setting the necessary options
     * for a React component to be memoized. In the main `moize`
     * method, if the `isReact` option is set it is short-circuited
     * to call this function, and these overrides allow the
     * necessary transformKey method to be derived.
     *
     * The order is based on:
     * 1) Set the necessary aspects of transformKey for React components.
     * 2) Allow setting of other options and overrides of those aspects
     *    if desired (for example, `isDeepEqual` will use deep equality).
     * 3) Always set `isReact` to false to prevent infinite loop.
     */ const reactMoizer = moizer ( { maxArgs : 2 , isShallowEqual : true , ... options , isReact : false , } ) ; if ( ! fn . displayName ) { fn . displayName = fn . name || 'Component' ; } function Moized < Props extends Record < string , unknown > , Context extends any , Updater extends any > ( this , props , context , updater ) { this . props = props ; this . context = context ; this . updater = updater ; this . MoizedComponent = reactMoizer ( fn ) ; } Moized . prototype . isReactComponent = { } ; Moized . prototype . render = function ( ) { return { $$typeof : REACT_ELEMENT_TYPE , type : this . MoizedComponent , props : this . props , ref : null , key : null , _owner : null , } as JSX . Element ; } ; copyStaticProperties ( fn , Moized , [ 'contextType' , 'contextTypes' ] ) ; Moized . displayName = `Moized(${ fn . displayName || fn . name || 'Component' })` ; setName ( Moized as MoizedFunction , fn . name , options . profileName ) ; return Moized ; }