Live data from Hacker News

A Primer for Building Single Page Applications with React

github.com

21–30 of 145 posts

Re: A Primer for Building Single Page Applications with React

#21

Honest question here from someone new to React. Isn't the way it mixes in HTML, CSS classes and JS altogether something we were trying to get away from a few years ago? It feels a bit like old school ASP! I'm not trying to be flippant, I just was always taught about separation and mixing HTML markup with JS logic seems like we are going the other way.

The idea was approximately that html was the data and css was the presentation. In reality they are quite connected and you have to write the html to support how it will be presented, a change to the presentation often requires a change to the data (html), and this doesn't really make sense.

I think a saner approach is to start with plain old data (e.g. some JSON) and have a function that can turn that into html/css/js. This is what react allows by using props/state as the input to the component/rendering function. It also permits you to pass complex objects as props/state but I like keeping to simple data as much as possible.

Re: A Primer for Building Single Page Applications with React

#22
post #15

What are your thoughts on, and how do you let your clients know (since you're a web agency?), that using anything built by Facebook comes with a huge business risk? With the included PATENTS file, if Facebook decides a patent they filed is something you violate then they will sue you or ask for a royalty. If you try to fight it or even suggest it's not valid then your license for React and all other Facebook projects…

It's undue paranoia. It says essentially the same thing as the Apache 'Grant of Patent License' section. Namely, if you instigate a patent lawsuit, the free patent license offered by Facebook no longer applies. It would be impossible for Facebook or Apache to engage in patent lawsuits if they did not include this termination clause. Besides, Facebook is gonna sue you if you violate their patents, regardless of whethe…

[deleted]

Re: A Primer for Building Single Page Applications with React

#23
post #22

Earlier quoted context omitted.

It's undue paranoia. It says essentially the same thing as the Apache 'Grant of Patent License' section. Namely, if you instigate a patent lawsuit, the free patent license offered by Facebook no longer applies. It would be impossible for Facebook or Apache to engage in patent lawsuits if they did not include this termination clause. Besides, Facebook is gonna sue you if you violate their patents, regardless of whethe…

[deleted]

No, this is not correct. Please stop spreading this misinformation.

Your license to use React is not contingent on 'not to sue them' – however, the additional patent grant that they give you is contingent on this. This patent grant is in addition to your license to use the software.

If you accuse Facebook of violating one of your patents, then you automatically lose the right to use any of theirs. You do not lose your license to use the software, which is a totally orthogonal issue.

Re: A Primer for Building Single Page Applications with React

#26

Please don't build single page applications. They drive me bananas. Consider how difficult it is to open different sections of your site into separate tabs.

Aren't you supposed to use react router and mimic the real site behavior in a single page app ?

Re: A Primer for Building Single Page Applications with React

#27

Honest question here from someone new to React. Isn't the way it mixes in HTML, CSS classes and JS altogether something we were trying to get away from a few years ago? It feels a bit like old school ASP! I'm not trying to be flippant, I just was always taught about separation and mixing HTML markup with JS logic seems like we are going the other way.

I do undestand where you come from there, but I'd view this as a bit different.

React's building block is the 'component' – the idea being that this is an isolated part of the application. By its very nature, isolating a component means separating the HTML from all the other HTML, and the script from all the other script.

Since components are generally quite small, it makes sense to bundle these together. You don't suffer the problems that encouraged people to separate concerns in the first place (things like have loads of interacting code that's duplicated and closely tied to structure), so it's OK to take a different approach – and I must say, in practice it works really well.

CSS is a separate issue – React doesn't mix CSS into the pot at all.

Re: A Primer for Building Single Page Applications with React

#28

Please don't build single page applications. They drive me bananas. Consider how difficult it is to open different sections of your site into separate tabs.

As esro360 said, goods router (like react-router) will keep your ability to open site links in different tabs, as well as keeping your location (and history) in sync with different views. Things have evolved since the first SPAs.
Post reply on HN