Discussion on: Thinking in React: The 2020 version

trimud profile image
Yuriy Boev

Hi and thanks for writing this article.

Out of curiosity - why do you need different FormInput and FormPasswordInput when you can pass the input type as prop?


lukeshiru profile image
▲ LUKE知る Author

Hi! Is just an abstraction so you can have separate behaviors/styles in those components down the line. Let's say for example that you want to add that 👁️ button some password fields have to show the password. If you had that directly in the Input then you need to add a ternary or if to show it only when type is "password", but with this approach you can have that button and all its styles encapsulated in the FormPasswordInput component.

Is funny how HTML has input with type to show all kinds of different elements, but for Headings they have h1, h2, h3, and so on.

Thanks a lot for taking the time to read and comment, Yuriy!