DEV Community

Jesse M. Holmes
Jesse M. Holmes

Posted on

Organizational Tacos: Sometimes It's Okay to Deviate from Familiar Patterns

Today we were discussing an application that has this very basic design:

<TacoContainer>
  {isTacoDetailsActive ?
    <TacoDetails /> :
    <TacoList /> }
</TacoContainer>
Enter fullscreen mode Exit fullscreen mode

Presentational and Container Component Pattern

This article isn't about the above pattern, so if you're already versed in its many names—e.g., here is a 2015 article on Medium by Dan Abramov bearing the same name—you may skip this brief section.

In the context of this application, TacoContainer is the component where all the action happens. It fetches data and maintains the state of isTacoDetailsActive, a variable we are using in this ternary statement that will determine which component is visible, TacoDetails or TacoList.

The other two components simply receive data from TacoContainer and display, or present them to the user. That's not to say they couldn't have their own state to manage, but for the purpose of this discussion, let's assume they do nothing other than display the many tacos we are about to enjoy or the complete details of an individual taco. If you're ever in Annapolis, MD, I will take you to the most authentic little diner with the best … actually, let me get back on track.

Ultimately, it is for you to decide

I remember spending hours on these kinds of details when I was learning Angular. There was an Angular way to do just about everything, and I wanted to create beautiful, conforming code that followed a plan.

In the end, there were things that didn't make sense for our team of two, so we made some changes. Eventually I learned that ultimately, it was for me to decide. That didn't protect me from making wrong decisions, but it did provide the freedom to learn and grow by attempting things outside of the norm.

The Question of the Day

Our discussion was based on this question: if TacoDetails and TacoList aren't sharing any state, and if they are both operating with independent data calls, is there anything wrong with moving that logic out of TacoContainer and into their respective components?

My answer: "Ultimately, it is for you to decide."

Temptation is a funny thing. Some run toward it as fast as possible, depending on what it is, and, after gaining a little experience, others will recognize temptation as the gateway to consideration. It's situational, of course. If I'm tempted to refactor my code, I pause and consider what it will be like for the developer who comes after me. I never pause and consider whether I should eat tacos. 🤷‍♂️🌮🌮🌮

Top comments (0)