Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is node js and JSX required for React JS

Tags:

reactjs

We have chosen the react JS 0.14.8 for front end because it supports IE 8 browser but Is Node JS or JSX is necessary for React JS development or we can create components without Node JS or Jsx

like image 871
Anurag Dadheech Avatar asked Nov 30 '22 15:11

Anurag Dadheech


2 Answers

Yes you can create ReactJs app without nodejs and jsx.

But why you should use JSX?

JSX provides a very clean way to declare your UI component. You can use your familiar html syntax to declare your user interface. JSX gets trans-piled and converted to light weight objects representing ui elements. e.g You can use following way to declare a react js via

1.jsx

const App = () => {
  return (
          <div><h1>Welcome to React</h1></div>
    );
}

or

2.without jsx

const App = function App() {
  return React.createElement(
    "div",
    null,
    React.createElement(
      "h1",
      null,
      "Welcome to React"
    )
  );
};

You can guess which one is easy to write.

Why should I use nodejs to build browser projects?

nodejs is never required for running websites on browser. But nodejs ecosystem provides you thousands of npm modules to use in your projects without reinventing them just for your projects.

Without nodejs you could have used cdn providers and added <script> tag to use any library. But with the use of module bundlers and static assets generator such as browserify and webpack you can leverage the powser of nodejs ecosystem directly in your web project( which does not require nodejs runtime environment but rather run in browser).

Below snippet use <script> tag to make reactjs available without nodejs.

const App = () => {
  return (
          <div><h1>Welcome to React</h1></div>
    );
}

ReactDOM.render(<App />, document.getElementById('app'));
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>

<div id="app">
</div>
like image 175
WitVault Avatar answered Dec 04 '22 01:12

WitVault


Is node js required for React JS?

Let me split the answer into 2 parts:

In Production:

Server Side: Not needed unless you are using Node.js to create a web server and server your ReactJS files.

Client Side: Only browser is enough.

In development:

Server Side: Needed to download react libraries and other dependencies using NPM. Needed by webpack to create production bundles.

Client Side: Only browser is enough.

Is JSX required for React JS?

Developer can use HTML tags directly inside javascript if JSX(javascript + XML tags) is used. otherwise it becomes difficult to write code as well as to understand the code.

Hope this answer helps, Thank you

like image 29
Basavaraj Hadimani Avatar answered Dec 04 '22 00:12

Basavaraj Hadimani