loading...

Discussion on: An Introduction to Reusable Components and how to create Typography Component

Collapse
devworkssimone profile image
DevWorksSimone

Nice, will try the challenges. Noob question... variant?variantsMapping[variant]:"p"; written this way will always output variantsMapping wheter it is in the mapping or not? I mean variant could be' any truthy value

Collapse
nghiemthu profile image
Thu Nghiem Author

Hi sorry for the late reply. variant ? variantsMapping[variant] : "p" means that

if (variant) {
return variantsMapping[variant];
} else {
return "p";
}
Collapse
devworkssimone profile image
DevWorksSimone

Ok bit even "bingobongo" is truthy that would lead to undefined or error doesnt it?

Thread Thread
nghiemthu profile image
Thu Nghiem Author

yeah good points. it will return undefined and error in that case :) good catch. usually, it will have propTypes or typescript to prevent those. but yeah we can add more check to this. But this is an example and the component is not fully complete.