3 ms·
You can use React in an MVC framework, with React used to implement the 'V' in MVC. You can use class components, and the code becomes extremely simple. Busines
by lateforwork 6mo ago
You can use React in an MVC framework, with React used to implement the 'V' in MVC. You can use class components, and the code becomes extremely simple. Business logic is moved to 'M' layer (models) and the 'C' layer (controllers) coordinates everything. No hooks or other messy stuff needed.
In fact, React was originally designed to be used this way (as the V in MVC)!
See https://github.com/Rajeev-K/mvc-router https://github.com/Rajeev-K/mvc-router
- bobthepanda 6mo agoYou can do this pretty simply with hooks and reducers, where the reducer/dispatch are the model/controller. Class components have their own pitfalls when you start messing around with componentDidUpdate, which was part of the motivation behind functional components IIRC.
- lateforwork 6mo agoNot everyone likes hooks. Class components may have issues, but if hooks are the solution I'll stay with class components, thank you very much!
- bobthepanda 6mo agoI will say that I used to really not like hooks and that’s because I think the migration documentation and messaging was handled pretty poorly. That being said, if you’ve worked with state management like Redux, I would argue that hooks are pretty similar to how you hook up that kind of data store.
- lateforwork 6mo agoYeah, Redux is another big mistake I stayed away from. "Line after line of throat clearing and pseduostructure", as one developer put it [1] [1] https://news.ycombinator.com/item?id=15342764 https://news.ycombinator.com/item?id=15342764