You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There just no code to handle this case. I was working for library that wraps components with proxy.
So full here typesafe implementation of wrapping components with proxy.
constREACT_MEMO_TYPE=Symbol.for("react.memo");constREACT_FORWARD_REF_TYPE=Symbol.for("react.forward_ref");constREACT_LAZY_TYPE=Symbol.for("react.lazy");// const enum LazyStatus {// Uninitialized = -1,// Pending = 0,// Resolved = 1,// Rejected = 2,// }typeRealComponentType<TPropsextendsobject,IRef=unknown>=|{$$typeof: typeofREACT_FORWARD_REF_TYPE;render: (props: TProps,ref: null|Ref<IRef>)=>ReactNode;}|{$$typeof: typeofREACT_MEMO_TYPE;compare: null|((a: TProps,b: TProps)=>boolean);type: (props: TProps)=>ReactNode;}|{$$typeof: typeofREACT_LAZY_TYPE;_status: -1|0|1|2;_result: unknown;}|React.ComponentClass<TProps>|React.FC<TProps>;typeReactFunctionalComponentType<TPropsextendsobject,IRef=unknown>=Extract<RealComponentType<TProps,IRef>,{$$typeof: typeofREACT_FORWARD_REF_TYPE}|React.FC<TProps>>;constwrapFunctionalFROrDefault=<TPropsextendsobject>(Component: ReactFunctionalComponentType<TProps>,handler: HocTransformer)=>{typeForwardRefComponent=Extract<ReactFunctionalComponentType<TProps>,{$$typeof: typeofREACT_FORWARD_REF_TYPE}>;typeRegularFunctionComponent=Exclude<ReactFunctionalComponentType<TProps>,ForwardRefComponent>;if("$$typeof"inComponent&&Component["$$typeof"]===REACT_FORWARD_REF_TYPE){return{$$typeof: REACT_FORWARD_REF_TYPE,render: newProxy((ComponentasForwardRefComponent).render,handler),};}returnnewProxy(ComponentasRegularFunctionComponent,handler);};// I don't know why but typescript is not helpful at all// Component can be memo class component or wrapped in hoc functional componentexportconstwrapComponentIntoHoc=<TPropsextendsobject>(Component: RealComponentType<TProps>,handler: HocTransformer,mimicToNewComponentHandler: null|MimicToNewComponentHandler)=>{// this case assumes that it's ClassComponentif(isClassComponent(Component)){returnwrapFunctionalFROrDefault(toFunctional(Component)asReact.FC<TProps>,handler);}if("$$typeof"inComponent&&Component["$$typeof"]===REACT_MEMO_TYPE){return{$$typeof: REACT_MEMO_TYPE,// @ts-expect-errortype: wrapFunctionalFROrDefault(toFunctional(Component.type),handler),compare: Component.compare,};}if("$$typeof"inComponent&&Component["$$typeof"]===REACT_FORWARD_REF_TYPE){return{$$typeof: REACT_FORWARD_REF_TYPE,// render is always functionrender: newProxy(Component.render,handler),};}if("$$typeof"inComponent&&Component["$$typeof"]===REACT_LAZY_TYPE){returnComponent;}constproxied=newProxy(Component,handler);returnmimicToNewComponentHandler
? newProxy(proxied,mimicToNewComponentHandler)
: proxied;};
The text was updated successfully, but these errors were encountered:
There just no code to handle this case. I was working for library that wraps components with proxy.
So full here typesafe implementation of wrapping components with proxy.
The text was updated successfully, but these errors were encountered: