React Basic :
React js is a library and it is used to develop single page applications. React js is a front-end technology and it is completely based on javascript.
To create a react project you need to install node js first.
Download node js from this link https://nodejs.org/en/
After successfully installing node js install react js by these commands, open your terminal and run these commands.
Now your react app will launch after running npm start command.
What is JSX :
JSX stands for syntax extension to javascript. Its kind of a template language with full power of javascript.
Inside react if we want to show a H1 tag without JSX then we need to write these long syntax.
Inside index.js file comment out the ReactDOM.render and create a element and render it inside the root id html element.
Output for the above code is
this way JSX works internally to create elements.
JSX format :
For one heading element it is easy to initialize but what happen when you have to write a lot of html code, Its complicated write React.createElement code for all html code.
To solve this we use JSX which allow you to write all the html code inside a javascript funciton and later this Babel convert automatically all html code to React.createElement javascript code.
Babel is a compiler used in react js for JSX conversion.
Now the same above output you can get with JSX by writing simple html code.
Now simple html h1 tag can be used inside this render function. This code writing inside the render function is JSX.
lets understand with another file.
create a Demo.js file inside the src folder
This is the code inside the Demo.js file
This above code represent JSX.
Now we will import this file inside index.js and use it inside the ReactDOM.render.
This will generate same output with text demo data.
This helps to show basic javascript errors during compilation.
That’s all for this post, feel free to comment if you have any question.
3 Comments