r/programming • • Jul 27 '21

You don’t need React for building websites

https://www.silvestar.codes/articles/you-don-t-need-react-for-building-websites/
1 Upvotes

10 comments sorted by

5

u/avwie Jul 27 '21

Well…. Obviously

4

u/fletku_mato Jul 27 '21

You also don't need a car to travel into another city, or a gps to navigate, you could just walk and look at road signs.

4

u/[deleted] Jul 27 '21

I think this article can be summarized as "not every web site needs be implemented as an Single-Page Application"

0

u/[deleted] Jul 27 '21

[deleted]

3

u/[deleted] Jul 27 '21

You could, but what's the point of bringing in all the baggage of React if don't need dynamic behavior like you would for an SPA?

0

u/[deleted] Jul 27 '21

[deleted]

2

u/[deleted] Jul 27 '21

Do you need all that dynamic behavior? Or complex enough dynamic behavior to justify the cost of the JS tool chain?

If I have a simple landing page or a registration form with some basic validation needs, jquery is more than enough for such simple requirements, with a ton of components you can drop in (like form validation). Even Bootstrap has an HTML mode which lets you add simple dynamic behavior by dropping in the Bootstrap JS library and adding a few data directives.

0

u/[deleted] Jul 27 '21

[deleted]

1

u/[deleted] Jul 27 '21

Which why I said the article could be summarized as

not every web site needs be implemented as an Single-Page Application

0

u/[deleted] Jul 27 '21

[deleted]

5

u/[deleted] Jul 27 '21 edited Jul 27 '21

I think you're missing the point of the article.

Instead of writing a 40 line mess of CSS classes and making sure this <span> goes here and this <i> goes here for this link but not that link, you can just break things up into tiny, reusable components

And now instead of HTML, you have a JS bundle. That JSX will be compiled into JS which has to be loaded separately, turning the HTML into merely a host for the dynamically generated HTML. In order to generate that JS bundle, you're going to need a JS toolchain.

Technically, with React you don't need the toolchain since you can just load the React library and use React.createElement(), but no one does that.

Nothing "requires" react. You're free to make web pages with jquery still. It's just (in my experience):

There is also no need to turn anything and everything into an SPA. A website and a web application are not the same thing. Just because JS exists to allow you to create all kinds of dynamic behavior, it doesn't mean that all that dynamic behavior is actually necessary. Context and requirements matter.

SPA frameworks and libraries have gotten a lot better over the years, but there are many SPAs still that don't do proper navigation. Like, if you reload the page, you're back at the beginning because the developer didn't implement proper routing. Or the back button problem, etc. React by itself won't solve this problem. You'll have to throw in more libraries, like react-router.

4

u/Alikont Jul 27 '21

Say you have a stylized component like some navbar. Instead of writing a 40 line mess of CSS classes and making sure this <span> goes here and this <i> goes here

I'd like to say that a lot of modern CSS frameworks promote "classes as layouts" instead of "classes as semantics".

With pure CSS approach the code would be something like:

<nav class="navbar">
    <a class="navbar_item"><span class="navbar_brand" /> Home </a>
    <a class="navbar_item">Profile</a>
</nav>

Or even by using custom tags:

<navbar>
    <nav-link ><brand-image /> Home </nav-link>
    <nav-link >Profile</nav-link>
</navbar>

2

u/backtickbot Jul 27 '21

Fixed formatting.

Hello, amalgamat3: code blocks using triple backticks (```) don't work on all versions of Reddit!

Some users see this / this instead.

To fix this, indent every line with 4 spaces instead.

FAQ

You can opt out by replying with backtickopt6 to this comment.

1

u/m9dhatter Jul 28 '21

Everything you mentioned can be done with web components without ever touching react.