Live data from Hacker News

Ask HN: How does one build large front end apps without a framework like React?

news.ycombinator.com

121–130 of 197 posts

Re: Ask HN: How does one build large front end apps without a framework like React?

#121
post #71

Earlier quoted context omitted.

I don't think this has to be true. If you think of a framework as a piece of code that calls you where you sort of supply it with configuration you could do that when writing vanilla js but you don't have to. When I write vanilla js I don't have a seperate file called framework.js. There is very little code needed to manage state. Almost all functions in my codebase are doing concrete things.

I mean in a complex enough application you'll have to come up with some abstractions that will make you life easier anyway. I doubt that you will manually add and remove classes, or add and remove nodes via direct DOM API calls every time you need to do that. You know what I mean? A set of such abstractions is what I call a framework. It doesn't have to be a separate file called "framework.js". It may even be more of…

I do use abstractions to make my life easier. The main abstraction is a function called tag:

    const tag = (tagName, props, ...children) => {
        const el = document.createElement(tagName)
        for(let k in props) el.setAttribute(k, props[k])
        for(let child of children)
            el.appendChild(typeof child == 'string'? document.createTextNode(child) : child)
        return el
    }
This makes the construction of new elments a bit more concise. The rest is just functions, manually adding or removing classes and adding or removing nodes via the direct DOM API.

The main advantage I think React brought is breaking the concept of "separation of concerns" (keeping css, html and js in different files even when they change together). Keeping stuff that belongs together in the same file and mostly pure is what gives the most benefit. You don't need complicated frameworks for that.

    const createSpecialButton = text => tag("button", {style: "background: purple"}, text)
When something becomes a framework is a bit blurry. I consider this more of an utility function. It is only 7 lines long. You call it, it does not call you. It gives you back a concrete element, not some abstract intermediate value. It is completely optional. The amount of these utilities you need in a big project is still tiny.

I wrote a figma clone (see other comment) with couple of these utility functions. It looks a lot like a regular react project really. Mostly functions (which you might call a component if they return HTML), mostly pure or local state.

Re: Ask HN: How does one build large front end apps without a framework like React?

#122

Earlier quoted context omitted.

> Hooks are only 5 years old. That is a long damn time in this industry, and class-based components still work just fine.

I preferred class based components. The pretend functional programming style of hooks is quite imperative when you prick a little beneath the surface, so classes were probably the right abstraction.

The problem with classes that hooks helped with was how hard it was to add multiple, reusable bits of lifecycle functionality. In even a medium size codebase I'd find myself having to reason about how to combine behavior A with behavior B in the onComponentWillWhatever methods. Hooks are weird but much much easier to compose and share.

Re: Ask HN: How does one build large front end apps without a framework like React?

#123
post #70

Earlier quoted context omitted.

If you are writing the same DOM update code in each event handler you can abstract it into a function.

What I'm saying, say you have 3 dependent dropdown pickers, selecting an item in the first one determine which of the other 2 are shown. When you have reactive interfaces like that, it's hard to extract the common "business" logic. Either you redraw everything from scratch or you do a sort of show/hide on DOM elements as in jQuery days. Not sure how you can abstract that. If you do abstract it, you end up with backbo…

    
        a
        b
    
    ...
    ...
    
        const $ = name => document.querySelector(name)
        $('#dropdown').addEventListener('change', ev => {
            $('#a').style.display = ev.target.value == "a"? "block" : "none"
            $('#b').style.display = ev.target.value == "b"? "block" : "none"
        }
    
vs

    const [showing, setShowing] = useState(null)
    const handleChange = ev => setShowing(ev.target.value)
    let other
    if(showing == "a") other = ...
    if(showing == "b") other = ...
    return 
        
            a
            b
        
        {other}
    
some notes:

- The complexities of both of these tiny pieces of code is similiar (I would say)

- React needs to load a big bundle

- React spits out a large stacktrace with react internals if something goes wrong

- React is slower

- React code cannot be easily stepped through with the debugger

- React needs a build step

- React performance is very unpredictable (this is more of a problem with many elements and dynamic code)

Your next question might be what you do once your form grows huge. See my other answer to @iliaznk how I handle that.

Re: Ask HN: How does one build large front end apps without a framework like React?

#124

HTML+CSS+JavaScript is already a massive framework and layer of abstraction. Try creating a GUI in C++ without using any libraries.

> Try creating a GUI in C++ without using any libraries.

This is more or less my response to anyone who complains about CSS; just consider the alternatves. CSS is, by an order of magnitude, the most powerful, flexible, accessible, and maintainable paradigm for UI development in existence. In some cases you're talking hundreds of native LOC to implement what a single CSS rule in a class can do.

Re: Ask HN: How does one build large front end apps without a framework like React?

#125

Earlier quoted context omitted.

> React is a lot more stable than I think you're giving it credit for. Hooks are only 5 years old. The docs were revamped 2 years ago and there's lots of dead links to the old docs page which has a scary warning "These docs are old and won’t be updated." Create-react-app was deprecated in February of this year and in their blog post they tell you to use frameworks like Next.js. And then there's the ecosystem. Next.js…

I'm gonna be honest, I've been developing with react for about 9 years across a lot of projects and companies. I've never used next. Maybe I'm out of touch, but I don't understand why people think it's so tightly could with the ecosystem

If you check the docs for how to create a react app the first thing they recommend is to use next.js.

Re: Ask HN: How does one build large front end apps without a framework like React?

#126

Earlier quoted context omitted.

None of these are problems taken separately, but put together they're pretty frustrating. Hooks being 5 years old and being the predominant tool for certain tasks shows that the community only figured out how to solve a particular problem 5 years ago. Compare that, in terms of stability, to Python having coming up with the idea of packages a long time ago, and packages are now a stable part of the ecosystem (packag i…

> None of these are problems taken separately, but put together they're pretty frustrating. Hooks being 5 years old and being the predominant tool for certain tasks shows that the community only figured out how to solve a particular problem 5 years ago. Hooks are ~~7~~ 6 years+8months old, almost 7 years. This may not seem like a significant difference, but IMO it puts them 75% of the way back in time to when react t…

> Hooks are ~~7~~ 6 years+8months old, almost 7 years. This may not seem like a significant difference, but IMO it puts them 75% of the way back in time to when react took off versus 50% of the way.

I don't disagree with your overall point here, but if you're going to be super nitpicky and pedantic about this, then you can't call 6 years and 8 months 75% of 10 years.

Re: Ask HN: How does one build large front end apps without a framework like React?

#127
My preferred stack:

- jQuery

- Typescript

- Tailwind

- Novel (https://github.com/owls-on-wires/novel)

- Some other small libraries for things like state management

- Webpack for bundling

An example of it in action: (https://mnty.sh/#serenity)

Re: Ask HN: How does one build large front end apps without a framework like React?

#128
post #70

Earlier quoted context omitted.

What I'm saying, say you have 3 dependent dropdown pickers, selecting an item in the first one determine which of the other 2 are shown. When you have reactive interfaces like that, it's hard to extract the common "business" logic. Either you redraw everything from scratch or you do a sort of show/hide on DOM elements as in jQuery days. Not sure how you can abstract that. If you do abstract it, you end up with backbo…

a b ... ... const $ = name => document.querySelector(name) $('#dropdown').addEventListener('change', ev => { $('#a').style.display = ev.target.value == "a"? "block" : "none" $('#b').style.display = ev.target.value == "b"? "block" : "none" } vs const [showing, setShowing] = useState(null) const handleChange = ev => setShowing(ev.target.value) let other if(showing == "a") other = ... if(showing == "b") other = ... retu…

Yes and then add few other pieces of state and interdependent components, the reactive code will extend, the manual patch job of connecting listeners and mutating DOM will start falling apart. The first example is okay for a one off but can't be reused as a component. It's also easy to get in a place where you have to update 3-4 different handlers to include a logic change. In a component based library/framework, you ideally update the state logic in one place and the UI just reflects that. For example, making the UI dynamic with a button that adds/removes multiple items that need this show/hide logic, you would need to attach new listeners, clean up listeners, clean up DOM items, and so on... my first example was only illustrative, but not to be taken literally. There a complex UI state in many apps, and reactivity with component based reuse is easier to manage and make sure all states are covered. Many times in my jquery years 10-15 years ago I had failed to update one piece of the DOM and there would be bugs that just aren't happening with component UIs.

Re: Ask HN: How does one build large front end apps without a framework like React?

#129

Earlier quoted context omitted.

I'm gonna be honest, I've been developing with react for about 9 years across a lot of projects and companies. I've never used next. Maybe I'm out of touch, but I don't understand why people think it's so tightly could with the ecosystem

If you check the docs for how to create a react app the first thing they recommend is to use next.js.

Oh interesting - I haven't been on their starting page in years. I'm surprised getting started with vite isn't higher up. That takes 5 minutes and doesn't require a full framework.

That said, starting with react router or expo is probably the right call depending on the project needs. Routing is not something you want to do yourself, and react native is pretty unfriendly without expo

Re: Ask HN: How does one build large front end apps without a framework like React?

#130
For me, it's Django templates + HTMX + vanilla JS when I absolutely need it. Crazy how far you can get with just this stack. I even did a technical spike for a realtime chat app recently with this, and it honestly performs better than some bloated JS monsters.
Post reply on HN