revite/src/redux/connector.tsx

17 lines
508 B
TypeScript
Raw Normal View History

2021-06-18 14:25:33 -04:00
/* eslint-disable @typescript-eslint/no-explicit-any */
2021-07-05 06:23:23 -04:00
import { connect, ConnectedComponent } from "react-redux";
2021-06-18 14:25:33 -04:00
import { h } from "preact";
2021-06-19 10:29:04 -04:00
import { memo } from "preact/compat";
2021-07-05 06:23:23 -04:00
import { State } from ".";
export function connectState<T>(
2021-07-05 06:25:20 -04:00
component: (props: any) => h.JSX.Element | null,
mapKeys: (state: State, props: T) => any,
memoize?: boolean,
): ConnectedComponent<(props: any) => h.JSX.Element | null, T> {
2021-07-05 06:25:20 -04:00
let c = connect(mapKeys)(component);
return memoize ? memo(c) : c;
}