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

Default props in React Component (Typescript)

$
0
0

I recently found a way to set default props on react components, like this:

type Props = {  children: any,  color?: keyof typeof textColors,};const GTitle: React.FC<Props> = ({ children, color }) => (<Title color={textColors[color]}>    {children}</Title>);GTitle.defaultProps = {  color: 'primary',};

the problem is that even if I define that there is a default property, the typescript keeps accusing the possibility of having an undefined value,as in the example below:

enter image description here


Viewing all articles
Browse latest Browse all 6287

Trending Articles



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