Interview question
What is React and why is it used? React क्या है और इसे क्यों use करते हैं?
Answer
React is a JavaScript library developed by Facebook for building user interfaces with reusable components. It uses a virtual DOM for efficient updates and enables building interactive single-page applications (SPAs).
| Feature | Description |
|---|---|
| Component-based | Build UI with reusable components |
| Virtual DOM | Efficient rendering with virtual representation |
| Unidirectional data flow | Easier debugging and data tracking |
| SEO friendly | Can be rendered on server-side |
| Large ecosystem | Rich libraries and tools available |
// Creating a basic React component
import React from 'react';
import ReactDOM from 'react-dom';
function App() {
return (
<div>
<h1>Welcome to React!</h1>
<p>React makes building UI easy and fun.</p>
</div>
);
}
// Rendering the component
ReactDOM.render(<App />, document.getElementById('root'));
// With React 18
import { createRoot } from 'react-dom/client';
const root = createRoot(document.getElementById('root'));
root.render(<App />);
// Why React?
// 1. Reusable components reduce code duplication
// 2. Virtual DOM improves performance
// 3. One-way data binding makes code predictable
// 4. Large community and ecosystem
// 5. Easy to learn and master
// 6. Used by major companies (Facebook, Netflix, Airbnb)React एक JavaScript library है Facebook द्वारा बनाई गई। Reusable components से UI बनाते हैं। Virtual DOM से efficient rendering होती है।
| Feature | Description |
|---|---|
| Component-based | Reusable components से UI बनाना |
| Virtual DOM | Efficient rendering |
| One-way data flow | Predictable data flow |
Was this answer clear?