i have a prop in a component which is onPress, when onPress is true, i want to render TouchableOpacity or View if onPress is false, this is my code:
const Card: FC<CardProps> = ({ title, subTitle, onPress }) => {
return (
<Container onPress={onPress}>
...
const Container = styled.View`
flex-direction: row;
padding-horizontal: 7px;
padding-vertical: 12px;
background-color: #fff;
shadow-opacity: 0.08;
shadow-radius: 25px;
elevation: 8;
shadow-color: rgb(0, 0, 0);
shadow-offset: 0px 1px;
border-radius: 8px;
margin-bottom: 10px;
`;
what i want to avoid is making another constant declaration, e.g.:
const TouchableContainer = styled.TouchableOpacity`
flex-direction: row;
padding-horizontal: 7px;
padding-vertical: 12px;
background-color: #fff;
shadow-opacity: 0.08;
shadow-radius: 25px;
elevation: 8;
shadow-color: rgb(0, 0, 0);
shadow-offset: 0px 1px;
border-radius: 8px;
margin-bottom: 10px;
`;
and do:
onPress? <ToucableContainer> : <Container>
cause it would feel redundant? i am confused with higher order component so i want to know what's the right approach to this? THanks