mirror of
https://github.com/reduxjs/redux-devtools.git
synced 2025-06-15 18:43:13 +03:00
* chore(deps): update dependency prettier to v3 * Format --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Nathan Bierema <nbierema@gmail.com>
31 lines
750 B
TypeScript
31 lines
750 B
TypeScript
import React, { ComponentType, ReactNode, Component } from 'react';
|
|
|
|
interface Mapper<In, Out> {
|
|
(inProps: In): Out;
|
|
}
|
|
|
|
interface MapPropsOutput<In, Out> {
|
|
(comp: ComponentType<Out>): ComponentType<In>;
|
|
}
|
|
|
|
export function mapProps<In, Out>(
|
|
mapper: Mapper<In, Out>,
|
|
): MapPropsOutput<In, Out> {
|
|
return function mapPropsHoc(Comp) {
|
|
class MapPropsHoc extends Component<In> {
|
|
render(): ReactNode {
|
|
const mappedProps = mapper(this.props);
|
|
|
|
// TODO Not really sure why this is needed, but it is
|
|
return <Comp {...(mappedProps as Out & JSX.IntrinsicElements)} />;
|
|
}
|
|
|
|
static displayName = `mapProps(${
|
|
Comp.displayName || Comp.name || 'Component'
|
|
})`;
|
|
}
|
|
|
|
return MapPropsHoc;
|
|
};
|
|
}
|