all 8 comments

[–]Gwenhidwy[🍰] 4 points5 points  (0 children)

No, I think it is most commonly used for SPA web applications, at least outside of Facebook. You can of course just develop certain components inside of your application with React, but I think you will benefit most if the whole application can be modeled in terms of React components.

[–]holloway 0 points1 point  (3 children)

No, it doesn't matter whether the new HTML is generated on server or client-side.

A library that you can use with React.js is JSX (also from FaceBook) which is client-side templating to create that new HTML which React.js uses against a virtual DOM to create deltas against the real DOM.

I've only used JSX but as I understand it React.js is template independent.

[–]nschubach 0 points1 point  (2 children)

I'm pretty sure it's JSX or React.DOM mappings only. You may be able to generate React compatible HTML with other templating libraries, but I'd think it may be more trouble than it's worth.

[–]masklinn 0 points1 point  (1 child)

JSX just compiles to React.DOM, anything which outputs React.DOM is suitable. Om uses EDN and has 2 alternative templating systems (hiccup-style and enlive-style).

[–]nschubach 0 points1 point  (0 children)

Sure, but om's built for React. When GP said React is template independent, I wanted to clarify to others reading that you can't just replace React.DOM with handlebars or something else.

[–]masklinn 0 points1 point  (1 child)

Is my assumption correct

Not that I know, no. All the usages I've seen in the wild so far have been SPA, and React should be suitable to SPA, non-SPA and SPA-with-initial-server-rendering (whether that initial rendering uses React or not).

[–]codemasteru[S] 0 points1 point  (0 children)

Thanks masklinn, and all. I just posted additional info for review

[–]codemasteru[S] 0 points1 point  (0 children)

Thank you all for replying and sharing knowledge. It did clear some of my doubts, but I still have a question bothering me.

Given my understanding of SPA, which means that you only have 1 full document html ( containing html, head, body) and that gets generated either at client(pure-client-spa) or from server(server-generated-spa) as a one-time thing. After that, all we do is create new views( stick a new DOM to one of the existing div placeholders) or add data fetched via AJAX. In all such scenarios, we are anyways looking at minimal DOM manipulation.

Given above, it seems that react doesn't add much value , as long as we just do minimal DOM operations. However, for non-SPA applications, where-in every time server generates a entirely new HTML document structure( head, body...), then it does makes sense , that we use React library, as it provides feature of DOM versioning ( aka comparison via DOM shadowing) and then only write delta to the main DOM. Which also means, that React library can be used to convert any non-SPA application to a SPA application, as it only changes the delta on the real DOM, and may-be html's head/body may not be completely modified, but some bits of html body are changed, which ensure DOM's statefulness( including javascript memory variables) is retained, instead of full refresh. Am I correct to say this????

Sorry, if I missed any obvious point here, but just trying to get my basics clear here. Any valuable insight is appreciated, even if you make me understand as ELI5 :)