You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+46-9Lines changed: 46 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -1366,8 +1366,7 @@ class ParentComponent extends React.Component {
1366
1366
**[⬆ Back to Top](#table-of-contents)**
1367
1367
1368
1368
26. ### What is children prop?
1369
-
1370
-
_Children_ is a prop that allows you to pass components as data to other components, just like any other prop you use. Component tree put between component's opening and closing tag will be passed to that component as `children` prop.
1369
+
The `children` prop is a special prop in React used to pass elements between the opening and closing tags of a component. It is commonly used in layout and wrapper componnents.
1371
1370
1372
1371
A simple usage of children prop looks as below,
1373
1372
@@ -1389,6 +1388,9 @@ class ParentComponent extends React.Component {
1389
1388
);
1390
1389
}
1391
1390
```
1391
+
Here, everything inside `<MyDiv>...</MyDiv>` is passed as children to the custom div component.
1392
+
1393
+
The children can be text, JSX elements, fragments, arrays and functions(for advance use case like render props).
1392
1394
1393
1395
<details><summary><b>See Class</b></summary>
1394
1396
<p>
@@ -1439,6 +1441,8 @@ class ParentComponent extends React.Component {
1439
1441
</div>
1440
1442
```
1441
1443
1444
+
You can use `//` and `/* */` in JS logic, hooks, and functions.
1445
+
1442
1446
**[⬆ Back to Top](#table-of-contents)**
1443
1447
1444
1448
28. ### What is reconciliation?
@@ -1478,13 +1482,46 @@ class ParentComponent extends React.Component {
1478
1482
1479
1483
30. ### Why React uses `className` over `class` attribute?
1480
1484
1481
-
The attribute names written in JSX turned into keys of JavaScript objects and the JavaScript names cannot contain dashes or reserved words, it is recommended to use camelCase wherever applicable in JSX code. The attribute `class` is a keyword in JavaScript, and JSX is an extension of JavaScript. That's the principle reason why React uses `className` instead of `class`. Pass a string as the `className` prop.
1485
+
React uses **className** instead of**class** because of a JavaScript naming conflict withthe classkeyword.
In JavaScript, classis used to define ES6 classes:
1489
+
1490
+
```js
1491
+
class Person {
1492
+
constructor(name) {
1493
+
this.name = name;
1494
+
}
1495
+
}
1496
+
```
1497
+
If you try to use classas a variable or property name, it will throw a syntax error. SinceJSX is just JavaScript withXML-like syntax, using classdirectlyinJSX would break the parser.
React then translates `className` to` class`in the final HTMLDOM.
1518
+
1519
+
3. Aligns withDOM APIs
1520
+
In vanilla JavaScript, you interact with element classes using:
1521
+
```js
1522
+
element.className = 'my-class';
1523
+
```
1524
+
React follows this convention, staying consistent with the DOMAPI's property name rather than HTML’s attribute.
1488
1525
1489
1526
**[⬆ Back to Top](#table-of-contents)**
1490
1527
@@ -1549,7 +1586,7 @@ class ParentComponent extends React.Component {
1549
1586
1550
1587
33. ### What are portals in React?
1551
1588
1552
-
_Portal_ is a recommended way to render children into a DOM node that exists outside the DOM hierarchy of the parent component. When using
1589
+
A Portal is a React feature that enables rendering children into a DOM node that exists outside the parent component's DOM hierarchy, while still preserving the React componenthierarchy. When using
1553
1590
CSS transform in a component, its descendant elements should not use fixed positioning, otherwise the layout will blow up.
0 commit comments