Showing posts with label React. Show all posts
Showing posts with label React. Show all posts

Monday, June 25, 2018

Custom Properties (Singel pattern)

I'm always trying to find ways to make my code more maintainable.  How many times have you come back to your code 2 months down the road only to ask yourself, "What's going on here?"  Admittedly, I have a short term memory, so it's definitely a good idea to use techniques that create self-documenting code, re-use common patterns and make it easy to hop in and add features without necessitating a 4 hour audit of the code first.

I recently read an article by Diego Haz that suggests that one favor creating more components versus simply passing in custom properties to determine how a component gets rendered.
Unless you're creating a well-documented open source library, resist that. Besides introducing the need of documentation, it's not scalable and will lead to unmaintainable code. Always try to create a new single element — such as AvatarRounded — which renders Avatar and modifies it, rather than adding a custom prop.
Diego admits that custom properties are not evil, but should only be used after carefully considering their need.