23 lines
858 B
TypeScript
23 lines
858 B
TypeScript
import { observer } from 'mobx-react-lite';
|
|
import type { ComponentType } from 'react';
|
|
import { useRowOptions } from 'stores/tables/insurance/hooks';
|
|
import { useInsuranceValue } from './hooks';
|
|
import type { Keys } from './types';
|
|
|
|
export function buildOptionComponent<T>(key: string, Component: ComponentType<T>, valueName: Keys) {
|
|
return observer((props: T) => {
|
|
const [value, setValue] = useInsuranceValue(key, valueName);
|
|
const options = useRowOptions(valueName);
|
|
|
|
return <Component value={value} options={options} setValue={setValue} {...props} />;
|
|
});
|
|
}
|
|
|
|
export function buildValueComponent<T>(key: string, Component: ComponentType<T>, valueName: Keys) {
|
|
return observer((props: T) => {
|
|
const [value, setValue] = useInsuranceValue(key, valueName);
|
|
|
|
return <Component value={value} setValue={setValue} {...props} />;
|
|
});
|
|
}
|