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

React Native Color Type with type script

$
0
0

I'm creating a simple component that accepts a color as a prop, and I'm using type script in my project and I want to force users to pass only valid color values to the component using type script type checking. how can I achieve this using react native? which types I should use?

const TextBody = ({  color}: {color: //Need This}) => {  return (<Text      style={[        generalStyles,        textTransformStyle,        textAlignStyle,        selfAlignmentStyle,        typography?.body,        style,      ]}>      {children}</Text>  );};export { TextBody };

users should be able to pass colors like following

<TextBody color="red"/><TextBody color="#21292F"/><TextBody color={rgba(12,2,1,0)}/>

And this should throw an error

<TextBody color={5252}/>

Viewing all articles
Browse latest Browse all 6287

Trending Articles



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