React.js (Introduction and Working)
Introduction to ReactJS: Let us understand this with a practical example.
Let’s say one of your friends posted a photograph on Facebook. Now you go and like the image and then you started checking out the comments too. Now while you are browsing over comments you see that the likes count has increased by 100, since you liked the picture, even without reloading the page. This magical count change is because of ReactJS.
React uses a declarative paradigm that makes it easier to reason about your application and aims to be both efficient and flexible. It designs simple views for each state in your application, and React will efficiently update and render just the right component when your data changes. The declarative view makes your code more predictable and easier to debug.
A React application is made of multiple components, each responsible for rendering a small, reusable piece of HTML. Components can be nested within other components to allow complex applications to be built out of simple building blocks. A component may also maintain an internal state – for example, a TabList component may store a variable corresponding to the currently open tab.
Note: React is not a framework. It is just a library developed by Facebook to solve some problems that we were facing earlier.
Prerequisites: Download Node packages with their latest version.
Example: Create a new React project by using the command below:
npx create-react-app myapp
Filename App.js: Now change the App.js file with the given below code:
Although React was conceived to be used in the browser, because of its design it can also be used in the server with Node.js.