Live data from Hacker News

Things every React.js beginner should know

camjackson.net

121–130 of 247 posts

Re: Things every React.js beginner should know

#121
post #64
post #24

Earlier quoted context omitted.

Putting HTML and JS in different files doesn't make them separated. They are still bound by logic. It's an imaginary separation with obscure dependencies. I very much prefer the React way of bundling things that in reality belong together.

It is quite possible to develop semantic, content focused HTML and then at a later point style and re-style with CSS. It is only through laziness and lack of understanding that people couple them together.

Except this isn't about style. It's about logic. Logic isn't as optional as style, and if you separate the logic into one JS file and the DOM into another HTML file, they are still tied together by the JS binding some action to some named DOM element (by selector, etc).

The separation that scales is the one that pairs a small piece of DOM (like a piece of text on the page that updates with the current stock price) to the JS that goes with it, and put that into a single file. Now, build your web page out of components instead.

Re: Things every React.js beginner should know

#122
post #78

What really bothers me about React (and other frameworks) that without JS you do not see anything. No fallback. No progressive enhancement. Is this really the way to go? Did JS replace HTML/CSS as the backbone of websites/applications ?

That's not generally true. React is specifically designed to support progressive enhancement. It lets you render your pages on the server, and then the client-side JavaScript will work smoothly with the existing DOM. Redux is a popular state management library for React and it is also specifically engineered to make server rendering painless. All you need to do on the server is load the relevant JSON state for the given URL and give it to React.

Re: Things every React.js beginner should know

#123

I'm not a React or Angular expert, but do you really put HTML inside of your JS code? It just bothers me too much. We spent years in early web days learning that code and templates should be separate, yet here we are putting HTML inside of code, which goes against years of practice. Can anyone share their professional thoughts about this?

This is a debate that has been going on since I started in the late 90ies. You need some sort of logic in your views, no matter what system you use, i. e. loops or formatting dates. Because people are raised on the "don't mix logic & layout" maxim, they feel dirty when they write sich logic in their usual language. .. so they invent template languages... ... that then expand to be turing-complete and basically offer…

Exactly. I'm only able to write such powerful React components by having a full programming language (JS) in my view (the React render method). The logic-less template approach would have been crippling for me.

Re: Things every React.js beginner should know

#124
post #78

What really bothers me about React (and other frameworks) that without JS you do not see anything. No fallback. No progressive enhancement. Is this really the way to go? Did JS replace HTML/CSS as the backbone of websites/applications ?

And without JS you don't get real applications on the web. Dumb text is fine for web 1.0, 2.0, but modern web applications are expanding far beyond that. Are there ways to be abusive with JS? Sure. But JS is what enables web applications as opposed to just having text-on-page (newspaper 2.0).

This is simply not true. Ignoring the fact that "real application on the web" has no definition... very useful web pages can be created without JavaScript, and they can (quite easily) interact with the user by taking input and updating what they display.

Why is something like that useful? Accessibility, security, backward compatibility, ...

Re: Things every React.js beginner should know

#125
post #99

Earlier quoted context omitted.

> In all fairness this is ancient history on the PHP world. No, because PHP still work that way (hypertext pre-processor) and Yes because, PHP has frameworks that makes PHP work like other solutions (Ruby,Python,Java + frameworks), but one still need a And again, a lot of PHP developers despise these frameworks and question their usefulness. In theory, they are right since PHP is a template language which goal is to…

I have no idea how starting with <?php in a file is relevant. Should we also start mocking languages that expect a given file extension?

My point is that PHP renders text first and foremost, writing code in PHP is "opt-in" somehow. An HTML file for instance is a valid PHP file. AFAIK an HTML file isn't a valid Ruby or Python file. You don't need to tell the interpreter to kick in at first place. But that's not the main idea I tried to convey in my comment.

Re: Things every React.js beginner should know

#126
post #78

What really bothers me about React (and other frameworks) that without JS you do not see anything. No fallback. No progressive enhancement. Is this really the way to go? Did JS replace HTML/CSS as the backbone of websites/applications ?

There are ways to render the output on the server, which helps search engines, first-page load times and Richard Stallman

+1 for the Stallman pun, so true

Re: Things every React.js beginner should know

#127
post #99
post #55

Earlier quoted context omitted.

In all fairness this is ancient history on the PHP world.

> In all fairness this is ancient history on the PHP world. No, because PHP still work that way (hypertext pre-processor) and Yes because, PHP has frameworks that makes PHP work like other solutions (Ruby,Python,Java + frameworks), but one still need a And again, a lot of PHP developers despise these frameworks and question their usefulness. In theory, they are right since PHP is a template language which goal is to…

> No, because PHP still work that way (hypertext pre-processor)

I think what the commenter is saying is no one builds like this anymore in PHP, regardless of whether or not you're using a framework.

Re: Things every React.js beginner should know

#128
post #44

Earlier quoted context omitted.

That is just inside of WPF-land, though. WinForms (which is still pretty excellent for quick-and-dirty GUIs) and other GUI frameworks are more on the classical model.

And UWP, which is the primary UI framework now.

Assuming that doesn't go the way of the host of other things that Microsoft has rolled out, spun their wheels on, and abandoned when it didn't take off.

WinAPI abides...

Re: Things every React.js beginner should know

#129
Fantastic article, in the past 9 months you've hit on nearly all of my discoveries.

Something I do now every time I create a new react app is to create a base class that extends React.Component that uses `PureRenderMixin`. When doing this I can prevent unnecessary renders from props changes. A killer of this would be passing an prop to a child that always changes its identity, like passing a function that calls `bind`, Because bind create a new method every time its call the identity always changes and the method will always be re-rendered. Knowing gotchas like these can help really speed up apps!

Post reply on HN