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

React Native with Typescript - Pressable pressed property

$
0
0

I am new using typescript with React and I cannot use pressed prop from Pressable in a react native app using typescript.

I am using styled components and defining a prop to change styles when Pressable is pressed:

interface Props {    isPressed: number;}const MyBTN = styled.Pressable<Props>`    background-color: blue;    border-radius: 5px;    display: flex;    align-items: center;    padding: 5px;    background-color: ${globalStyle.primaryColor};    box-shadow: 30px 25px 25px black;    elevation: ${(props) => props.isPressed};`;const TrainerButton: React.FC<Deck> = ({title, onPress}) => {return (<MyBTN onPress={onPress} isPressed={({ pressed } : any) => pressed ? 10 : 15}><Text>            { title }</Text></MyBTN>    )}

I get an error on the pressed prop isPressed={({ pressed } : any) => pressed ? 10 : 15}:

No overload matches this call.Overload 1 of 2, '(props: Omit<Omit<PressableProps & RefAttributes & Props, never> & Partial<Pick<PressableProps & RefAttributes & Props, never>>, "theme"> & { ...; } & { ...; }): ReactElement<...>', gave the following error.Type '({ pressed }: any) => 10 | 15' is not assignable to type 'number'.

Overload 2 of 2, '(props: StyledComponentPropsWithAs<ForwardRefExoticComponent<PressableProps & RefAttributes>, DefaultTheme, Props, never, ForwardRefExoticComponent<...>, ForwardRefExoticComponent<...>>): ReactElement<...>', gave the following error.Type '({ pressed }: any) => 10 | 15' is not assignable to type 'number'.ts(2769)

thank you!


Viewing all articles
Browse latest Browse all 6287

Trending Articles



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