DEV Community

Discussion on: Let's build a 3-in-1 form field component

Collapse
 
lyqht profile image
Estee Tey

Sure! This is a good resource on the Switch Statement code smell.

In the example you have given, you were checking the if condition props.type === someType on this component and return the appropriate component. For 3 types of components, the code seems fine, but if we expand the InputField component to have more types, it will become difficult to navigate this code. And for other types of InputField components, you might also want different validation instead of a catch-all validateInput() method.

So i'm just curious how would you address these issues šŸ˜„

Thread Thread
 
gedalyakrycer profile image
Gedalya Krycer

These are good points. To be honest Iā€™m not sure. :) I suspect it might come down to breaking out the more complex form fields into their own components.