Live data from Hacker News

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

news.ycombinator.com

151–160 of 197 posts

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

#151
post #96

I build a lot of micro sites, but I still use frameworks — like Deno (node alternative), Hono (for APIs), and Alpine.js (for tiny lightweight sites). you don't have to though! if you want to do more pure vanilla, understanding signals is really useful — this basically powers svelte's runs and react's hooks and whatever. I love nanostores, a 286 byte (!) state manager that lets you build highly reactive pages w/o the…

+1 for nanostores. It's great that it works standalone, but what's also nice is that they have tools to let you use it with React. It's much cleaner and more intuitive than React contexts which is how you're supposed to do global state in React, I think.

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

#152

Earlier quoted context omitted.

I mainly use React via Reagent in ClojureScript, and literally have no use cases where I need to use useState/useEffects for anything. Turning it around, what exactly are you unable to do without useState/useEffects?

When I want to memoize something slightly complex, for simplicity's sake let's say sorting an array of objects based on one of it's keys. I can put that in a useMemo and it won't sort it again when the page eventually rerenders for some reason. Usually that array is mapped elsewhere and those child components might also re render if the array is recalculated. useEffects are when I need to call something outside of re…

> I can put that in a useMemo and it won't sort it again when the page eventually rerenders for some reason

useMemo dependency smell. This is almost always because your dependencies are wrong. This can often happen if you put a dependency as [object] instead of [object.field] due to how JavaScript maps objects to memory.

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

#153

Vanilla JS is very powerful and has the features you need to build SPAs without a big framework. Proxies and mutation observers are great for maintaining state, Updating the DOM yourself is fine, view transitions are awesome, etc. The only thing that's hard is routing, but there are lots of small dedicated JS libraries to handle that. Here's one I made that gives you the Express API on the frontend: https://github.co…

VanillaJS has no inbuilt type checking and your project will collapse under the weight of itself once reaching a certain size.

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

#154

Vanilla JS is very powerful and has the features you need to build SPAs without a big framework. Proxies and mutation observers are great for maintaining state, Updating the DOM yourself is fine, view transitions are awesome, etc. The only thing that's hard is routing, but there are lots of small dedicated JS libraries to handle that. Here's one I made that gives you the Express API on the frontend: https://github.co…

VanillaJS has no inbuilt type checking and your project will collapse under the weight of itself once reaching a certain size.

What are you talking about with this talk of implosion? It sounds like boogieman nonsense from small children scared of the dark. I prefer to use vanilla JS when writing large SPAs and it works just fine.

There is a stereotype from the outside world that a great many programmers are autistic. The irrational fear of not using a framework for code in the browser is one of those cases that really screams the stereotype for all to see.

If you are using TypeScript there is inbuilt type checking for the DOM, because TypeScript ships with a very good data type library that describes the DOM in excellent detail.

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

#155

Earlier quoted context omitted.

VanillaJS has no inbuilt type checking and your project will collapse under the weight of itself once reaching a certain size.

What are you talking about with this talk of implosion? It sounds like boogieman nonsense from small children scared of the dark. I prefer to use vanilla JS when writing large SPAs and it works just fine. There is a stereotype from the outside world that a great many programmers are autistic. The irrational fear of not using a framework for code in the browser is one of those cases that really screams the stereotype…

> What are you talking about with this talk of implosion? It sounds like boogieman nonsense from small children scared of the dark. I prefer to use vanilla JS when writing large SPAs and it works just fine.

It’s absolutely not and it absolutely doesn’t. Inheriting a VanillaJS project is often a nightmare because it screams “inexperienced developer” not to use a framework, so the code quality and build processes are often extremely low quality and undocumented.

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

#156

I've abandoned Next.js and React for Elixir / Phoenix. I am able to build a perfectly pleasant user experience with just a sprinkle of vanilla JS via Phoenix hooks. The fact that I have been able to build a multi-user collaborative editor experience without a single additional dependency is incredible. I previously worked for a well-established and well-funded React team who had this feature on their roadmap for half…

I'm curious what is specific to Phoenix that made this so productive for that project? Is the frontend using something like HTMX?

The big win for me has been the built-in PubSub primitives plus LiveView. Since the backend is already maintaining a WebSocket connection with every client, it's trivial to push updates.

Here is an example. Imagine something like a multiplayer Google Forms editor that renders a list of drag-droppable cards. Below is a complete LiveView module that renders the cards, and subscribes to "card was deleted" and "cards were reordered" events.

```

  defmodule MyApp.ProjectLive.Edit do
    use MyApp, :live_view
    import MyApp.Components.Editor.Card

    def mount(%{"project_id" => id}, _session, socket) do
      # Subscribe view to project events
      Phoenix.PubSub.subscribe(MyApp.PubSub, "project:#{id}")
      project = MyApp.Projects.get_project(id)

      socket =
        socket
        |> assign(:project, project)
        |> assign(:cards_drag_handle_class, "CARD_DRAG_HANDLE")

      {:ok, socket}
    end

    def handle_info({:cards, :deleted, card_id}, socket) do
      # handle project events matching signature: `{:cards, :deleted, payload}`
      cards = Enum.reject(socket.assigns.project.cards, fn card -> card.id == card_id end)
      project = %{socket.assigns.project | cards: cards}
      socket = assign(socket, :project, project)
      # LiveView will diff and re-render automatically
      {:noreply, socket}
    end

    def handle_info({:cards, :reordered, card_change_list}, socket) do
      # omitted for brevity, same concept as above
      {:noreply, socket}
    end

    def render(assigns) do
      ~H"""
      
        {@project.name}
        
        
          
        
      
      """
    end
  end
```

What would this take in a React SPA? Well of course there are tons of great tools out there, like Cloud Firestore, Supabase Realtime, etc. But my app is just a vanilla postgres + phoenix monolith! And it's so much easier to test. Again, just using the built-in testing libraries.

For rich drag-drop (with drop shadows, auto-scroll, etc.) I inlined DragulaJS[1] which is ~1000 lines of vanilla .js. As a React dev I might have been tempted to `npm install` something like `react-beautiful-dnd`, which is 6-10x larger, (and is, I just learned, now deprecated by the maintainers!!)

The important question is, what have I sacrificed? The primary tradeoff is that the 'read your own writes' experience can feel sluggish if you are used to optimistic UI via React setState(). This is a hard one to stomach as a react dev. But Phoenix comes with GitHub-style viewport loading bars which is enough user enough feedback to be passable.

p.s. guess what Supabase Realtime is using under the hood[2] ;-)

[1] https://bevacqua.github.io/dragula/ [2] https://supabase.com/docs/guides/realtime/architecture

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

#157

It’s always mildly amusing how many engineers believe that React is a framework. I personally attribute it to lack of experience—once you’ve used enough proper frameworks, you’d laugh at that comparison. The fact that React is and always has been literally defined as a library right on its website doesn’t seem to stop them. Incidentally, many of the issues people have with React are attributable to this mistake: know…

If you go to the React website you need to click "Learn React". A library often does not make you learn new concepts. It is just functions with input and output. On the first page "Quickstart" all code blocks contain code that contain JSX and call you. They do not even show the part where you need to call render. Copying this code into your codebase will not do anything. On that same page they also introduce state ma…

> If you go to the React website you need to click "Learn React".

The second library I remembered (GSAP) writes exactly that on their site.

> A library often does not make you learn new concepts

New concepts are absolutely a thing, take any library that implements any spec and in order to use that library you have to learn subject domain of the spec.

Another example is D3 (the first library I thought of), which does not exactly has “Learn D3” (quite an unorthodox way of assessing whether something is a framework anyway) but which does require you learn a bunch of concepts to use it in an educated way. Just like people do with React, you can obviously not learn these concepts and wing it, and then reap the consequences of resulting awkward code.

> Sure you can theoratically use react as a library but I've never seen it

It is not “used as a library”. It is a library. Being mistaken for a framework is why projects often get burned. People who are aware that it is a library, and use it as such, tend to not to get burned, because then you know you have to either have a simple project, or implement all the framework-y elements that it misses, usually part by strategically picking a set of other libraries to fill in the blanks and part DIY.

Show me a complex project that is not using a framework and I will show you a home-made framework.

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

#158

It’s always mildly amusing how many engineers believe that React is a framework. I personally attribute it to lack of experience—once you’ve used enough proper frameworks, you’d laugh at that comparison. The fact that React is and always has been literally defined as a library right on its website doesn’t seem to stop them. Incidentally, many of the issues people have with React are attributable to this mistake: know…

https://en.wikipedia.org/wiki/Software_framework >

Yup.

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

#159
post #95

Earlier quoted context omitted.

Framework is unfortunately a term that's both ill-defined and quite overloaded. Electron is a framework in a very different sense than the "JS frameworks" op is asking about. The latter is about libraries with APIs and mental models for producing the UI & UX of web applications. Electron is just a way of running Chrome without the Chrome UI around it, + a few APIs for accessing native OS APIs. You wouldn't say that C…

> Electron is a framework in a very different sense than the "JS frameworks" op is asking about. The OP doesn't have a good understanding of what they're asking about, and that's okay. That's why they asked the question. The linked thread is titled "What framework did the developer use to create Obsidian desktop application?". It's not asking about a web application and specifically referencing a desktop framework wi…

[deleted]

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

#160
post #136

Earlier quoted context omitted.

Everyone else in this thread is talking about (React/Angular/Vue/JQuery/etc) v.s. (Plain JS/Direct DOM manipulation/etc). Running that code on top of Electron or not is entirely orthogonal. So I admit I'm confused why you're fixated on bringing Electron into the conversation. Op's question appears to me like it references the last part of the linked thread: "I’d like to know what JavaScript framework (e.g. Vue, React…

I thought we were talking about this (pasted from your comment above): > "I’d like to know what JavaScript framework (e.g. Vue, React) Obsidian desktop application is using for creating the user interface? And the answer to that question is: Electron. Is that not the question?

[deleted]
Post reply on HN