@applicaster/zapp-react-native-utils
Version:
Applicaster Zapp React Native utilities package
26 lines (18 loc) • 761 B
text/typescript
import * as React from "react";
import { MeasurementPortalContext } from "@applicaster/zapp-react-native-ui-components/Components/MeasurmentsPortal";
import { noop } from "@applicaster/zapp-react-native-utils/functionUtils";
type MeasuredHeight = number | undefined;
export const useMeasurement = ({ renderComponent }): MeasuredHeight => {
const [height, setHeight] = React.useState<MeasuredHeight>(undefined);
const { measureComponent } = React.useContext(MeasurementPortalContext);
React.useEffect(() => {
(async () => {
const props = {
onLoadFinished: noop,
};
const result = await measureComponent(renderComponent, props); // HEAVY OPERATION
setHeight(result.height);
})();
}, []);
return height;
};