A day that really brought home the importance of algorithms..
In my current project, I’m building a category page that renders nested categories, each with up to four children, as a tree component. Meeting the requirements for this component involves a lot of logic for finding values within the nested structure. Recursion is unavoidable in these cases, but because I’m not familiar with these algorithms, the code hasn’t come easily.
The need for a new component structure
When developing a new feature, its components often look broadly similar to existing ones, but the detailed design measurements and typography differ. Sometimes the internal logic needs to change too. What’s the best approach in those cases? Previously, I created new components that overrode existing ones. But as this kept happening, I found myself producing the same components and repeating the same work, so I started looking for another approach.
- Separate the view from the logic
- Compound Component pattern
- Function as Children Component pattern
- Custom Hook pattern
→ With a headless approach, styles are usually applied through className.
Is there a better way??? —> I’ll be back with a post about improving these components.
I’m making a similar hook for the third time… Is this normal…?
I’ve made a filter query hook for the third time.
Isn’t reuse the whole point of a hook?
If it can’t be reused, is it really fulfilling that role?
Why I made a new one instead of reusing it:
- They all manage filters by sending the overall query to the router.
- The query types and the conditions each query needs are different.
- For example, changing the sort order should also reset pagination on some pages. Other pages use infinite scrolling. It’s hard to unify the handleSort logic.
Still, wouldn’t it be possible if I separated the logic well enough? —> Let’s take more interest in functional programming and study it.
Futsal and swimming
I’d only been swimming, but I’ve started futsal too. Maybe that’s too much cardio, but I enjoy it more than strength training. Could my body and mind feel any healthier? This is the first time I’ve exercised consistently for a whole month, and every day is a dopamine rush. Let’s keep going.
One-line takeaway
Keep asking what I’m needlessly repeating every day, and keep improving it.
July goals
-
Tackle algorithms:
I’m planning a month-long algorithm sprint. I’ll first practice getting familiar with common coding interview patterns like DFS and BFS! -
Keep blogging: Stop leaving drafts sitting around; polish them and publish them.
-
Dig deeper: I can’t keep stopping at quick fixes. Start with why and work toward a solution.
-
Next topics to explore
- Try all the React 18 and 19 features
- Samsung and Safari: resolve cross-browser issues
- Study functional programming
- Build a polymorphic component