17 lines
504 B
TypeScript

import { observer } from 'mobx-react-lite';
import type { ComponentType } from 'react';
import { useValue } from 'stores/calculation/values/hooks';
import type { Values } from 'stores/calculation/values/types';
type BuilderProps = {
valueName: Values;
};
export default function buildReadonly<T>(Component: ComponentType<T>, { valueName }: BuilderProps) {
return observer((props: T) => {
const [value] = useValue(valueName);
return <Component value={value} readOnly {...props} />;
});
}