DEV Community

Discussion on: Why Is This An "Anti-Pattern" in React???

Collapse
 
bytebodger profile image
Adam Nathaniel Davis

Finally, I like how you point out the potential similarities with Redux (umm... sorta) and MobX (much closer). I'll freely admit that, in a "corporate" coding environment, if given the choice between using my custom technique or using MobX, I'd probably just use MobX. My technique and MobX both allow for a shared reference to functions (as opposed to serializable data).

But I wouldn't want to move the functions out of their original components. IMHO, if a component does "a thing", then I want to see all the functions that are specifically used to do "that thing" right there, in that component. But I freely admit that this bias is more of my own personal coding preference.

There is a practical reason for keeping the functions with their original components, however. That reason is: state management/updates. I've found that this technique can wander into bizarre territory if I'm trying to setState() in a given component - but the function that accomplishes the setState() is not in its original component.