mirror of
https://github.com/reduxjs/redux-devtools.git
synced 2025-06-16 19:13:21 +03:00
* fix(deps): update all non-major dependencies * weird --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Nathan Bierema <nbierema@gmail.com>
31 lines
726 B
TypeScript
31 lines
726 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 any)} />;
|
|
}
|
|
|
|
static displayName = `mapProps(${
|
|
Comp.displayName || Comp.name || 'Component'
|
|
})`;
|
|
}
|
|
|
|
return MapPropsHoc;
|
|
};
|
|
}
|