( WrappedComponent: React.ComponentType<P>, // We do not want to have `updateProps` given in options, it is instead filled through the HOC. options?: Pick<Partial<ProfilerProps>, Exclude<keyof ProfilerProps, 'updateProps' | 'children'>>, )
| 152 | */ |
| 153 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 154 | function withProfiler<P extends Record<string, any>>( |
| 155 | WrappedComponent: React.ComponentType<P>, |
| 156 | // We do not want to have `updateProps` given in options, it is instead filled through the HOC. |
| 157 | options?: Pick<Partial<ProfilerProps>, Exclude<keyof ProfilerProps, 'updateProps' | 'children'>>, |
| 158 | ): React.FC<P> { |
| 159 | const componentDisplayName = |
| 160 | options?.name || WrappedComponent.displayName || WrappedComponent.name || UNKNOWN_COMPONENT; |
| 161 | |
| 162 | const Wrapped: React.FC<P> = (props: P) => ( |
| 163 | <Profiler {...options} name={componentDisplayName} updateProps={props}> |
| 164 | <WrappedComponent {...props} /> |
| 165 | </Profiler> |
| 166 | ); |
| 167 | |
| 168 | Wrapped.displayName = `profiler(${componentDisplayName})`; |
| 169 | |
| 170 | // Copy over static methods from Wrapped component to Profiler HOC |
| 171 | // See: https://reactjs.org/docs/higher-order-components.html#static-methods-must-be-copied-over |
| 172 | hoistNonReactStatics(Wrapped, WrappedComponent); |
| 173 | return Wrapped; |
| 174 | } |
| 175 | |
| 176 | /** |
| 177 | * |
no test coverage detected