-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathreact_tutorial copy.html
More file actions
428 lines (378 loc) · 14.3 KB
/
react_tutorial copy.html
File metadata and controls
428 lines (378 loc) · 14.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>React.js Interview Questions</title>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
<style>
/* General Styles */
body {
font-family: 'Arial', sans-serif;
background: #f4f4f4;
margin: 0;
padding: 0;
transition: 0.3s;
}
.dark-mode {
background: #222;
color: #fff;
}
/* Header */
header {
background: #2c3e50;
color: #fff;
padding: 10px 20px;
display: flex;
justify-content: space-between;
align-items: center;
position: sticky;
top: 0;
z-index: 1000;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}
.logo {
font-size: 24px;
font-weight: bold;
color: #fff;
}
nav ul {
list-style: none;
margin: 0;
padding: 0;
display: flex;
align-items: center;
}
nav ul li {
margin-left: 25px;
}
nav ul li a {
color: #fff;
text-decoration: none;
font-weight: bold;
font-size: 16px;
transition: color 0.3s ease;
}
nav ul li a:hover {
color: #ff6f61;
}
.hamburger {
display: none;
font-size: 24px;
cursor: pointer;
}
/* Main Content */
.container {
max-width: 900px;
margin: 20px auto;
padding: 20px;
background: #fff;
border-radius: 10px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
.dark-mode .container {
background: #333;
box-shadow: 0 4px 8px rgba(255, 255, 255, 0.2);
}
h1 {
text-align: center;
color: #007bff;
}
.search-box {
padding: 10px;
width: 80%;
max-width: 400px;
border: 1px solid #ccc;
border-radius: 5px;
font-size: 16px;
margin: 20px auto;
display: block;
}
.toggle-btn {
background: #008CBA;
color: white;
padding: 10px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
margin: 10px auto;
display: block;
transition: background 0.3s ease;
}
.toggle-btn:hover {
background: #005f73;
}
/* Sections */
.section {
background: #f9f9f9;
padding: 15px;
margin: 10px 0;
border-radius: 10px;
cursor: pointer;
border-left: 5px solid #007bff;
transition: transform 0.3s ease, box-shadow 0.3s ease;
}
.section:hover {
transform: translateY(-5px);
box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
}
.content {
display: none;
padding: 15px;
background: #fff;
border-left: 5px solid #007bff;
color: black;
margin: 10px 0;
border-radius: 10px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
.dark-mode .content {
background: #444;
color: white;
border-left: 5px solid #008CBA;
}
pre {
background: #1e1e1e;
color: lime;
padding: 15px;
border-radius: 5px;
overflow-x: auto;
position: relative;
}
.copy-btn {
position: absolute;
top: 10px;
right: 10px;
background: #007bff;
color: white;
border: none;
padding: 5px 10px;
border-radius: 3px;
cursor: pointer;
transition: background 0.3s ease;
}
.copy-btn:hover {
background: #0056b3;
}
textarea {
width: 100%;
height: 100px;
font-family: monospace;
margin-top: 10px;
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
font-size: 14px;
}
.run-btn {
color: white;
padding: 8px 16px;
border: none;
border-radius: 5px;
cursor: pointer;
margin-right: 10px;
transition: background 0.3s ease;
}
.run-btn:hover {
background: #218838;
}
a {
display: block;
text-align: center;
margin-top: 20px;
color: white;
text-decoration: none;
border-radius: 5px;
transition: background 0.3s ease;
}
a:hover {
background: #0056b3;
}
/* Footer */
footer {
background: #1a252f;
color: #fff;
text-align: center;
padding: 20px;
margin-top: 20px;
}
footer p {
margin: 0;
}
/* Responsive Design */
@media (max-width: 768px) {
.hamburger {
display: block;
}
nav ul {
display: none;
flex-direction: column;
width: 100%;
background: #2c3e50;
position: absolute;
top: 60px;
left: 0;
}
nav ul.active {
display: flex;
}
nav ul li {
margin: 10px 0;
text-align: center;
}
.header h3 {
font-size: 24px;
}
.search-box {
width: 90%;
}
.run-btn{
background:#000
}
}
</style>
</head>
<body>
<!-- Header -->
<header>
<div class="logo">Learn Coding</div>
<nav>
<ul class="menu">
<li><a href="#home">Home</a></li>
<li><a href="#tutorials">Tutorials</a></li>
<li><a href="#topics">Topics</a></li>
<li><a href="#testimonials">Testimonials</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
<div class="hamburger" onclick="toggleMenu()">☰</div>
</nav>
</header>
<!-- Main Content -->
<div class="container">
<h1>Top 30 React.js Interview Questions</h1>
<input type="text" id="search" class="search-box" placeholder="🔍 Search topics..." onkeyup="searchTopics()">
<button class="toggle-btn" onclick="toggleDarkMode()">🌙 Toggle Dark Mode</button>
<!-- Sections -->
<div id="topics-container">
<!-- Questions will be dynamically added here -->
</div>
</div>
<!-- Footer -->
<footer id="contact">
<p>© 2023 Learn Coding. All rights reserved.</p>
</footer>
<script>
const topics = [
["What is React?", "React.js is a JavaScript library for building fast and interactive user interfaces. It is maintained by Facebook."],
["What are Components in React?", "Components are reusable UI elements in React. They can be **class-based** or **functional**."],
["What is JSX?", "JSX (JavaScript XML) allows you to write HTML inside JavaScript."],
["What is State in React?", "State allows React components to **manage dynamic data**."],
["What are Props?", "Props (short for properties) are used to **pass data** between components."],
["What is the Virtual DOM?", "The Virtual DOM is a **lightweight copy** of the actual DOM that React updates efficiently."],
["What is useEffect?", "useEffect is a **React Hook** for handling side effects like fetching data."],
["What is React Router?", "React Router enables **navigation** in React applications."],
["What are React Hooks?", "React Hooks let you **use state and lifecycle methods** inside functional components."],
["What is useRef?", "useRef allows referencing **DOM elements** without re-rendering."],
["What is Context API?", "The **Context API** avoids prop drilling by sharing data globally."],
["What is memoization in React?", "Memoization optimizes performance by **caching results** of expensive computations."],
["What are controlled and uncontrolled components?", "A controlled component manages its **own state**, while an uncontrolled component relies on the DOM."],
["What is lazy loading in React?", "Lazy loading loads components **only when needed**, improving performance."],
["How to implement dark mode in React?", "Dark mode changes the background and text color based on user selection."],
["What is Redux and why is it used?", "Redux is a **state management library** that helps manage global state in large applications."],
["What is React.memo?", "React.memo is used to **optimize functional components** by preventing unnecessary re-renders."],
["What is useCallback and useMemo?", "Both useCallback and useMemo optimize performance by **memoizing values and functions**."],
["What is Server-Side Rendering (SSR) in React?", "Server-Side Rendering (SSR) generates pages **on the server** instead of the client."],
["What is Suspense in React?", "Suspense **handles lazy loading** and asynchronous data fetching."],
["What is React Context API?", "Context API is used to manage global state without prop drilling."],
["What is React Router?", "React Router helps in **navigation between pages** in a React app."],
["What is Prop Drilling?", "Prop drilling occurs when props are passed **multiple levels down** unnecessarily."],
["What are Controlled vs Uncontrolled Components?", "Controlled components are managed by React state, while uncontrolled components rely on the DOM."],
["What is React Portals?", "React Portals allow rendering elements outside their parent DOM hierarchy."],
["What is the difference between useEffect and useLayoutEffect?", "<strong>useEffect</strong> runs after rendering, while <strong>useLayoutEffect</strong> runs before painting the screen."],
["What is React.lazy?", "React.lazy allows **lazy loading** components to improve performance."],
["What is React.Fragment?", "React.Fragment allows grouping multiple elements without adding extra DOM nodes."],
["What is Concurrent Mode in React?", "Concurrent Mode makes React apps more responsive by **prioritizing updates efficiently**."]
];
const menuData = [
{
title: "Basic Math",
subMenu: [
{ name: "Trigonometry", link: "Trigonometry" },
{ name: "Algebra", link: "Algebra" },
{ name: "Geometry", link: "Geometry" },
]
},
{
title: "Tutorial",
subMenu: [
{ name: "React.js Tutorial", link: "react_tutorial" },
{ name: "Node.js Tutorial", link: "node_tutorial" },
{ name: "JavaScript Tutorial", link: "JavaScript_tutorial" }
]
}
];
const menuContainer = document.querySelector('.menu');
menuData.forEach(menuItem => {
const li = document.createElement('li');
const subMenu = document.createElement('ul');
subMenu.classList.add('sub-menu');
menuItem.subMenu.forEach(subItem => {
subMenu.innerHTML += `<li><a href="${subItem.link}">${subItem.name}</a></li>`;
});
li.appendChild(subMenu);
menuContainer.appendChild(li);
});
// Toggle Mobile Menu
function toggleMenu() {
const menu = document.querySelector('.menu');
menu.classList.toggle('active');
}
const topicsContainer = document.getElementById('topics-container');
topics.forEach((topic, index) => {
topicsContainer.innerHTML += `
<div class="section" onclick="toggleContent('q${index + 1}')">
<h2>${index + 1}️⃣ ${topic[0]}</h2>
</div>
<div id="q${index + 1}" class="content">
<p>${topic[1]}</p>
<textarea id="code${index + 1}">${topic[1]}</textarea><br>
<button class="run-btn" onclick="runCode('code${index + 1}')">Run</button>
<button class="copy-btn" onclick="copyToClipboard('code${index + 1}')">Copy</button>
</div>
`;
});
function toggleContent(id) {
let content = document.getElementById(id);
content.style.display = (content.style.display === "none" || content.style.display === "") ? "block" : "none";
}
function toggleDarkMode() {
document.body.classList.toggle("dark-mode");
Swal.fire("🌙 Dark mode " + (document.body.classList.contains("dark-mode") ? "enabled" : "disabled"));
}
function searchTopics() {
let input = document.getElementById("search").value.toLowerCase();
let sections = document.getElementsByClassName("section");
for (let section of sections) {
if (section.textContent.toLowerCase().includes(input)) section.style.display = "";
else section.style.display = "none";
}
}
function copyToClipboard(codeId) {
let codeElement = document.getElementById(codeId);
codeElement.select();
document.execCommand("copy");
Swal.fire("✅ Code copied!");
}
function runCode(codeId) {
let code = document.getElementById(codeId).value;
try { eval(code); }
catch (error) { Swal.fire("❌ Error: " + error.message); }
}
function toggleMenu() {
const menu = document.querySelector('.menu');
menu.classList.toggle('active');
}
</script>
</body>
</html>