To be honest I am not very familiar with "code smell of switch statements". Could you further elaborate on what the potential issues would be by utilizing a switch statement?
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 š
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.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
To be honest I am not very familiar with "code smell of switch statements". Could you further elaborate on what the potential issues would be by utilizing a switch statement?
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-allvalidateInput()
method.So i'm just curious how would you address these issues š
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.