3 ms·
> he problem that I find, especially in the React community is the belief that everything should be done in the framework. How do you make an API call in React?
by void_mint 6y ago
> he problem that I find, especially in the React community is the belief that everything should be done in the framework. How do you make an API call in React? How do you change the page title in React? How do you convert a string to an integer in React? People create libraries that are closely coupled to React when 90% of what they're trying to achieve could be a plain Javascript module. This isn't just React, its most of the frontend Javascript frameworks.
This matches my experience as well. It feels kinda wild - lots of other areas have taught to separate concerns as much as possible, meaning React would just be a View layer that renders content but is unrelated to the rest of the application. In reality, everything seems to get stuffed into React, such that React becomes your entire application.
- richeyryan 6y ago"React would just be a View layer that renders content but is unrelated to the rest of the application" This is how I treat it. React or more generally the view handles form state and stuff like modal visibility. Things that a user can interact with so to speak. I have a lib folder that which is the library of my business logic. Concepts related to our domain, analytics, validation, captchas etc. Some of it is shared between client and server, some of it is specific to either. Then I have my data layer. From my experience a lot of the data handling is interacting nodes (or stores) that can update asynchronously and react to each other. I use Effector (https://effector.dev https://effector.dev) to declaratively map all this. For example when a user submits their details it triggers the recaptcha check which if successsful triggers the saving of a user and the creation of a lead and once we have a lead token we navigate to the next page in the flow. Handling logic like that in React can really complicate components and the primitives in React aren't really well suited to it. So I found Effector and its been great. The added bonus is it makes the React components responsible for one thing, which is capturing user interaction. They capture events and forward them into Effector. The React code is clean and if I want to drastically change the UI or alter the flow everything is loosely coupled. Overall I'm quite skeptical of anything that reinforces this all in one approach to things. I appraise the pitched value and figure out how it can be achieved in a more separate way. The answers might not be immediately obvious and it might not be as easy to get started but I feel the overall result has been great so far.
- void_mint 6y agoI haven't worked in React (or frontend) in a long time, but your response is similar to how I have/would try to think about those problems. It seemed (when I was paying attention to React) that thinking was less common and most tools pushed you away from it? Which also kind of pushed me away from React as a tool.
- richeyryan 6y agoReact and frontend in general has a new starters problem. Its a lot of people's first interaction with tech. For better or worse I feel a lot of library maintainers and community aim to cater to the beginner. On one hand it makes things accessible and lets people get their start in the way I could mess around with CSS on MySpace or other people could copy code out of computer magazines. On the other hand, it leads to what we might call the PHP problem. Lots of low skill, low experience developers influencing what solutions and approaches become conventional. I've found people in the community that share my general outlook and I follow what they're doing. I also act as my own compass, letting my experience and the lessons I've learned from other ecosystems like Clojure and OCaml guide my approach. I'm at a stage in my career where I'm leading projects and can lay out the full vision. The developers I work with seem to appreciate the value in my approach and the problems I'm solving so its working out for now. I'm also gently trying to advocate on here and on Reddit and write blog posts to show how this stuff can be done. I don't think it will change the direction of the community but it at least clarifies what I think and why I think it.