Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

Types for Higher-order component with Styled components

$
0
0

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?


Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>