Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
641 views
in Technique[技术] by (71.8m points)

reactjs - How to pass all props to styled component in React Native with TypeScript?

I have a styled component:

const Wrapper = styled.View`
  align-items: center;
  flex-direction: row;
`;

I have a component which is using this styled component:

interface ProfileInfoBar extends ViewProps {}
const ProfileInfoBar: React.FC<ProfileInfoBar> = ({ ...rest }) => {
  return (
    <Wrapper {...rest}>
      <Avatar firstname="A" lastname="B" size={60} />
    </Wrapper>
  );
};

But I am getting an error when trying to pass rest to Wrapper:

No overload matches this call. Overload 1 of 2, '(props: Pick<Pick<ViewProps & RefAttributes, "hitSlop" | "onLayout" | "pointerEvents" | "removeClippedSubviews" | "style" | "testID" | "nativeID" | ... 48 more ... | "key"> & Partial<...>, "hitSlop" | ... 54 more ... | "key"> & { ...; } & { ...; } & { ...; }): ReactElement<...>', gave the following error. Type '{ children: Element[]; hitSlop?: Insets | undefined; onLayout?: ((event: LayoutChangeEvent) => void) | undefined; pointerEvents?: "none" | "auto" | "box-none" | "box-only" | undefined; ... 48 more ...; accessibilityIgnoresInvertColors?: boolean | undefined; }' is not assignable to type 'Pick<Pick<ViewProps & RefAttributes, "hitSlop" | "onLayout" | "pointerEvents" | "removeClippedSubviews" | "style" | "testID" | "nativeID" | ... 48 more ... | "key"> & Partial<...>, "hitSlop" | ... 54 more ... | "key">'. Types of property 'style' are incompatible.

enter image description here

I can't understand how to pass all props to styled component. Any ideas?

question from:https://stackoverflow.com/questions/65905593/how-to-pass-all-props-to-styled-component-in-react-native-with-typescript

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...