I'm trying to create a factory function to create components, but I cannot get the types correct.
Below I use it with Inner
, but ultimately, I would like to be able to use this function with any component that has style.marginTop
.
This is far as I have gotten:
const Inner = styled.View` margin-right: auto;`;type InnerProps = React.ComponentProps<typeof Inner>;const withOffset = <T/*,*/>( Component: React.ComponentType<T>) => (props: T): ReactElement => { const { top } = useSafeArea(); const { style, ...restProps } = props; const newStyle = { marginTop: top, ...StyleSheet.flatten(style) }; return <Component style={newStyle} {...restProps} />;};export const InnerWithOffset = withOffset<Inner>( Inner);
How do I write the types for this case?