Mathieu Mathieu - 1 year ago 77
React JSX Question

Should I recreate all my page from scratch (html and css) if I begin using React/flux?

I have alreayd built a few pages of my app. As i need a javascript framework and sub second dynamic pages I think I'll try React/Flux.

The thing is despite much reading, I don't fully understand if you can keep my EXISTING codebase (html/js) and only use React (jsx , modules) on certain blocks of the web page that need interaction with database/dynamic actualization?

Let's take an example:
my page has a lot of stuff : bootstrap I adjusted a lot(with css) that is actually using behind the scene javascript/the DOM ex for dropdowns, and other stuff), respond.js for enabling media queries on ie8 (using I guess the DOM), and many third party tools like or even google analytics js tracking window on the bottom of my screen.
you can see here what the pages look like.

enter image description here

My need: I just need dynamic adjustments and real time features on the block (D), all the other, the header (B), intercom(C) and the rest could stay like they are, it would save me some much time if i can keep them in their current html code.

So here are my question:

  • (1) do I have to convert EVERYTHING on the page on react or only put in jsx/react the block (D) and keep the rest as it is ?

  • Related to (1) I want to leverage the main advantage brought by React (the virtual DOM and the diffs), would I still be able to use it EVEN if the whole page is not on React ?

  • If the answer is basically "it's all or nothing, you've got to do it ALL in react jsx and redo your whole page", convert your html and find alternatives to all your js scripts that use the DOM such as dropdowns, light boxes, script, google analytics scripts then is it hard? i mean or can i keep the css and just use this to change the html ? that would be really easy but i fear there is a catch here...:)

Answer Source

In terms of the view layer of your app everything can be done with React (Yes react can do everything you require)

The first thing I would suggest is to head to the react site for the docs, do a few tutorial use Google & YouTube and then start to re-build your app from fresh with react but not entirely. (Use JSX).

Because you now understand how React works and how to use props and states you will likely end up merging fragments of your app at a time.

The most important thing to consider is context. React is simply Javascript so you can bind, call and apply any objects from your existing app.

var blockA = React.createClass~
    blockB = React.createClass~
    blockC = React.createClass~
    blockD = React.createClass~

React is just components, each block is a component.

But I can't stress more, understand the basic principles of react, it's not hard at all.


YES use JSX I thought it was stupid initially but it's excellent!

With DOM manipulation it's all or nothing. React uses its copy of the DOM to manipulate the actual DOM faster. For parts of you code that doesn't touch the DOM it will not make a huge difference in React but React has a beautiful workflow by passing state changes down to its component's children. Really it's up to you but If you are using React do all DOM stuff in react. 70+% of what you are trying to do is likely DOM manipulation.

My advice in general, don't think too much about how "hard" it will be. Think about how quick you can learn the basics. It's quite easy to grasp.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download