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

Can I extend a component's constructor with additional arguments?

$
0
0

Consider a sample component:

enum PET_TYPE {  CAT = 'cat',  DOG = 'dog',  OTHER = 'other',}interface Props {  type: PET_TYPE}function Pet(props: Props) {  switch (props.type) {    case PET_TYPE.CAT: return (<>MEOW!</>);    case PET_TYPE.DOG: return (<>WOFF!</>);    default:           return (<>HELLO</>);  }}Pet.PET_TYPE = PET_TYPE;export default Pet;

That will be used like this:

import Pet from "./Pet";<Pet type={Pet.PET_TYPE.CAT} />

Do you think that the addition of PET_TYPE as an attribute of the component constructor is something that can be done or should it be avoided?


Viewing all articles
Browse latest Browse all 6214

Trending Articles



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