Best Practices - separating business logic from UI

So, I've seen this pattern which the Business logic is put into a hook, so it doesn't bloat the component. I've also seen that some critics that having the business logic into the component is wrong Here's a stackoverflow thread that illustrates well what I'm talking about: https://stackoverflow.com/questions/69332889/reactjs-separation-of-ui-and-business-logic Now, is this separation the correct way to do it, or not really? If so, how is the file structure for that?
Stack Overflow
Reactjs separation of UI and business logic
I am new to react and I find it sore in the eyes to look at the component flooded with lots of functions and variable initializations together with the UI. Is it possible to separate them? Instead ...
10 Replies
kewinzaq1
kewinzaq13y ago
Stack Overflow
Reactjs separation of UI and business logic
I am new to react and I find it sore in the eyes to look at the component flooded with lots of functions and variable initializations together with the UI. Is it possible to separate them? Instead ...
deforestor
deforestorOP3y ago
But is it conventional? I mean, seems like a great pattern, but I'm afraid to bloat the files
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
deforestor
deforestorOP3y ago
That's what I thought too. Why make abstractions where abstractions aren't needed?
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
deforestor
deforestorOP3y ago
YES That's exactly what I thought. I feel like people who made that comment are the ones who came from hardcore OOP and want to OOPify React
tropic
tropic3y ago
Everytime i see someone post a ooped reqct code i vomit on the inside
deforestor
deforestorOP3y ago
this is the philosophy I've been living by and I spend waaay less time planning and much more time doing
isaac_way
isaac_way3y ago
one of the best parts of react is that you can colocate your UI and related business logic. It’s actually really good from a dev exp perspective. IMO it’s pretty easy to make a react codebase less maintainable if you’re breaking up stuff to quickly. Theo’s take is vry good here
Want results from more Discord servers?
Add your server