Skip to content

Commit 18826d2

Browse files
committed
Fix formatting issues
1 parent 69ec0ae commit 18826d2

File tree

1 file changed

+29
-27
lines changed

1 file changed

+29
-27
lines changed

README.md

+29-27
Original file line numberDiff line numberDiff line change
@@ -978,6 +978,7 @@
978978
2. If you extract list item as separate component then apply _keys_ on list component instead of `li` tag.
979979
3. There will be a warning message in the console if the `key` prop is not present on list items.
980980
4. The key attribute accepts either string or number and internally convert it as string type.
981+
5. Don't generate the key on the fly something like `key={Math.random()}`. Because the keys will never match up between re-renders and DOM created everytime.
981982
982983
**[⬆ Back to Top](#table-of-contents)**
983984
@@ -1354,7 +1355,7 @@
13541355
{children}
13551356
</div>;
13561357
);
1357-
};
1358+
}
13581359

13591360
export default function Greeting() {
13601361
return (
@@ -1916,21 +1917,22 @@
19161917
19171918
Keys should be stable, predictable, and unique so that React can keep track of elements.
19181919
1919-
In the below code snippet each element's key will be based on ordering, rather than tied to the data that is being represented. This limits the optimizations that React can do.
1920+
In the below code snippet each element's key will be based on ordering, rather than tied to the data that is being represented. This limits the optimizations that React can do and creates confusing bugs in the application.
19201921
19211922
```jsx harmony
19221923
{
19231924
todos.map((todo, index) => <Todo {...todo} key={index} />);
19241925
}
19251926
```
19261927
1927-
If you use element data for unique key, assuming todo.id is unique to this list and stable, React would be able to reorder elements without needing to reevaluate them as much.
1928+
If you use element data for unique key, assuming `todo.id` is unique to this list and stable, React would be able to reorder elements without needing to reevaluate them as much.
19281929
19291930
```jsx harmony
19301931
{
19311932
todos.map((todo) => <Todo {...todo} key={todo.id} />);
19321933
}
19331934
```
1935+
**Note:** If you don't specify `key` prop at all, React will use index as a key's value while iterating over an array of data.
19341936
19351937
**[⬆ Back to Top](#table-of-contents)**
19361938
@@ -7272,30 +7274,30 @@ const loadUser = async () => {
72727274
72737275
336. ### What is strict mode in React?
72747276
7275-
`React.StrictMode` is a useful component for highlighting potential problems in an application. Just like `<Fragment>`, `<StrictMode>` does not render any extra DOM elements. It activates additional checks and warnings for its descendants. These checks apply for _development mode_ only.
7277+
`React.StrictMode` is a useful component for highlighting potential problems in an application. Just like `<Fragment>`, `<StrictMode>` does not render any extra DOM elements. It activates additional checks and warnings for its descendants. These checks apply for _development mode_ only.
72767278
7277-
```jsx harmony
7278-
import React from "react";
7279+
```jsx harmony
7280+
import React from "react";
72797281

7280-
function ExampleApplication() {
7281-
return (
7282-
<div>
7283-
<Header />
7284-
<React.StrictMode>
7285-
<div>
7286-
<ComponentOne />
7287-
<ComponentTwo />
7288-
</div>
7289-
</React.StrictMode>
7290-
<Header />
7291-
</div>
7292-
);
7293-
}
7294-
```
7282+
function ExampleApplication() {
7283+
return (
7284+
<div>
7285+
<Header />
7286+
<React.StrictMode>
7287+
<div>
7288+
<ComponentOne />
7289+
<ComponentTwo />
7290+
</div>
7291+
</React.StrictMode>
7292+
<Header />
7293+
</div>
7294+
);
7295+
}
7296+
```
72957297
7296-
In the example above, the _strict mode_ checks apply to `<ComponentOne>` and `<ComponentTwo>` components only. i.e., Part of the application only.
7298+
In the example above, the _strict mode_ checks apply to `<ComponentOne>` and `<ComponentTwo>` components only. i.e., Part of the application only.
72977299
7298-
**[⬆ Back to Top](#table-of-contents)**
7300+
**[⬆ Back to Top](#table-of-contents)**
72997301
73007302
337. ### What is the benefit of strict mode?
73017303
@@ -7341,16 +7343,16 @@ const loadUser = async () => {
73417343
**[⬆ Back to Top](#table-of-contents)**
73427344
73437345
339. ### What are the rules of JSX?
7344-
The below 3 rules needs to be followed while using JSX in a react application.
7346+
The below 3 rules needs to be followed while using JSX in a react application.
73457347
7346-
1. **Return a single root element**:
7348+
1. **Return a single root element**:
73477349
If you are returning multiple elements from a component, wrap them in a single parent element. Otherwise you will receive the below error in your browser console.
73487350
73497351
```html Adjacent JSX elements must be wrapped in an enclosing tag.```
73507352
7351-
2. **All the tags needs to be closed:**
7353+
2. **All the tags needs to be closed:**
73527354
Unlike HTML, all tags needs to closed explicitly with in JSX. This rule applies for self-closing tags(like hr, br and img tags) as well.
7353-
3. **Use camelCase naming:**
7355+
3. **Use camelCase naming:**
73547356
It is suggested to use camelCase naming for attributes in JSX. For example, the common attributes of HTML elements such as `class`, `tabindex` will be used as `className` and `tabIndex`.
73557357
**Note:** There is an exception for aria-* and data-* attributes which should be lower cased all the time.
73567358

0 commit comments

Comments
 (0)