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

Is it a bad practice to pass props by spreading an object immediately defined

$
0
0

I know we can pass an object as props to a child in React by spreading an object which has the same keys as the expected props:

<SummaryPage     {...parentProps}    currentPeriodType={currentPeriodType}    missingCategories={missingCategories}/>

But are there any disavantages to doing it with all the props, even ones that are defined immediatly like this:

<SummaryPage  {...{     ...parentProps,     currentPeriodType,     missingCategories,  }}/>

I can see advantages in this, in that you don't have to repeat the name if it's the same as the prop's name, and that it's easier to move the data somewhere else as an object if it's necessary (not having to change the JSX syntax to object syntax).

As I was posting this question I noticed that apparently typescript's typechecking doesn't work for this format, which seems to be a greater drawback than the advantages I raised. But are there any other disadvantages?


Viewing all articles
Browse latest Browse all 6287

Trending Articles