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
+26-26Lines changed: 26 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -369,7 +369,7 @@ You can download the PDF and Epub version of this repository from the latest run
369
369
370
370
1.### What is React?
371
371
372
-
React is an **open-source frontend JavaScript library**which is used for building user interfaces especially for singlepage applications. It is used for handling view layer for web and mobile apps. React was created by [Jordan Walke](https://github.com/jordwalke), a software engineer working for Facebook. React was first deployed on Facebook's News Feed in 2011 and on Instagram in 2012.
372
+
React is an **open-source front-end JavaScript library**that is used for building user interfaces, especially for single-page applications. It is used for handling view layer for web and mobile apps. React was created by [Jordan Walke](https://github.com/jordwalke), a software engineer working for Facebook. React was first deployed on Facebook's News Feed in 2011 and on Instagram in 2012.
373
373
374
374
375
375
**[⬆ Back to Top](#table-of-contents)**
@@ -463,7 +463,7 @@ You can download the PDF and Epub version of this repository from the latest run
463
463
464
464
There are two possible ways to create a component.
465
465
466
-
1.**Function Components:** This is the simplest way to create a component. Those are pure JavaScript functions that accept props object as first parameter and return React elements:
466
+
1.**Function Components:** This is the simplest way to create a component. Those are pure JavaScript functions that accept props object as the first parameter and return React elements:
467
467
468
468
```jsx harmony
469
469
function Greeting({ message }) {
@@ -530,7 +530,7 @@ You can download the PDF and Epub version of this repository from the latest run
530
530
531
531

532
532
533
-
State is similar to props, but it is private and fully controlled by the component. i.e, It is not accessible to any other component til the owner component decides to pass it.
533
+
State is similar to props, but it is private and fully controlled by the component ,i.e., it is not accessible to any other component till the owner component decides to pass it.
534
534
535
535
536
536
**[⬆ Back to Top](#table-of-contents)**
@@ -797,7 +797,7 @@ You can download the PDF and Epub version of this repository from the latest run
797
797
}
798
798
}
799
799
```
800
-
2. You can also use ref callbacks approach regardless of React version. For example, the search bar component's input element accessed as follows,
800
+
2. You can also use ref callbacks approach regardless of React version. For example, the search bar component's input element is accessed as follows,
801
801
```jsx harmony
802
802
classSearchBarextendsComponent {
803
803
constructor(props) {
@@ -823,7 +823,7 @@ You can download the PDF and Epub version of this repository from the latest run
823
823
```
824
824
825
825
You can also use *refs* in function components using **closures**.
826
-
**Note**: You can also use inline ref callbacks even though it is not a recommended approach
826
+
**Note**: You can also use inline ref callbacks even though it is not a recommended approach.
827
827
828
828
**[⬆ Back to Top](#table-of-contents)**
829
829
@@ -1045,7 +1045,7 @@ You can download the PDF and Epub version of this repository from the latest run
1045
1045
1046
1046
It's worth mentioning that React internally has a concept of phases when applying changes to the DOM. They are separated as follows
1047
1047
1048
-
1. **Render** The component will render without any side-effects. This applies for Pure components and in this phase, React can pause, abort, or restart the render.
1048
+
1. **Render** The component will render without any sideeffects. This applies to Pure components and in this phase, React can pause, abort, or restart the render.
1049
1049
1050
1050
2. **Pre-commit** Before the component actually applies the changes to the DOM, there is a moment that allows React to read from the DOM through the `getSnapshotBeforeUpdate()`.
1051
1051
@@ -1077,9 +1077,9 @@ You can download the PDF and Epub version of this repository from the latest run
1077
1077
1078
1078
React 16.3+
1079
1079
1080
-
- **getDerivedStateFromProps:** Invoked right before calling `render()` and is invoked on *every* render. This exists for rare use cases where you need derived state. Worth reading [if you need derived state](https://reactjs.org/blog/2018/06/07/you-probably-dont-need-derived-state.html).
1080
+
- **getDerivedStateFromProps:** Invoked right before calling `render()` and is invoked on *every* render. This exists for rare use cases where you need a derived state. Worth reading [if you need derived state](https://reactjs.org/blog/2018/06/07/you-probably-dont-need-derived-state.html).
1081
1081
- **componentDidMount:** Executed after first rendering and where all AJAX requests, DOM or state updates, and set up event listeners should occur.
1082
-
- **shouldComponentUpdate:** Determines if the component will be updated or not. By default it returns `true`. If you are sure that the component doesn't need to render after state or props are updated, you can return false value. It is a great place to improve performance as it allows you to prevent a re-render if component receives new prop.
1082
+
- **shouldComponentUpdate:** Determines if the component will be updated or not. By default, it returns `true`. If you are sure that the component doesn't need to render after the state or props are updated, you can return a false value. It is a great place to improve performance as it allows you to prevent a re-render if component receives a new prop.
1083
1083
- **getSnapshotBeforeUpdate:** Executed right before rendered output is committed to the DOM. Any value returned by this will be passed into `componentDidUpdate()`. This is useful to capture information from the DOM i.e. scroll position.
1084
1084
- **componentDidUpdate:** Mostly it is used to update the DOM in response to prop or state changes. This will not fire if `shouldComponentUpdate()` returns `false`.
1085
1085
- **componentWillUnmount** It will be used to cancel any outgoing network requests, or remove all event listeners associated with the component.
@@ -1135,7 +1135,7 @@ You can download the PDF and Epub version of this repository from the latest run
1135
1135
1136
1136
*Context* provides a way to pass data through the component tree without having to pass props down manually at every level.
1137
1137
1138
-
For example, authenticated user, locale preference, UI theme need to be accessed in the application by many components.
1138
+
For example, authenticated users, locale preferences, UI themes need to be accessed in the application by many components.
@@ -1146,9 +1146,9 @@ You can download the PDF and Epub version of this repository from the latest run
1146
1146
1147
1147
38. ### What is children prop?
1148
1148
1149
-
*Children* is a prop (`this.props.children`) that allow 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.
1149
+
*Children* is a prop (`this.props.children`) 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.
1150
1150
1151
-
There are a number of methods available in the React API to work with this prop. These include `React.Children.map`, `React.Children.forEach`, `React.Children.count`, `React.Children.only`, `React.Children.toArray`.
1151
+
There are several methods available in the React API to work with this prop. These include `React.Children.map`, `React.Children.forEach`, `React.Children.count`, `React.Children.only`, `React.Children.toArray`.
1152
1152
1153
1153
A simple usage of children prop looks as below,
1154
1154
@@ -1199,7 +1199,7 @@ You can download the PDF and Epub version of this repository from the latest run
1199
1199
1200
1200
40. ### What is the purpose of using super constructor with props argument?
1201
1201
1202
-
A child class constructor cannot make use of `this` reference until `super()` method has been called. The same applies for ES6 sub-classes as well. The main reason of passing props parameter to `super()` call is to access `this.props` in your child constructors.
1202
+
A child class constructor cannot make use of `this` reference until the `super()` method has been called. The same applies to ES6 sub-classes as well. The main reason for passing props parameter to `super()` call is to access `this.props` in your child constructors.
1203
1203
1204
1204
**Passing props:**
1205
1205
@@ -2217,7 +2217,7 @@ You can download the PDF and Epub version of this repository from the latest run
2217
2217
2218
2218
87. ### Why should component names start with capital letter?
2219
2219
2220
-
If you are rendering your component using JSX, the name of that component has to begin with a capital letter otherwise React will throw an error as unrecognized tag. This convention is because only HTML elements and SVG tags can begin with a lowercase letter.
2220
+
If you are rendering your component using JSX, the name of that component has to begin with a capital letter otherwise React will throw an error as an unrecognized tag. This convention is because only HTML elements and SVG tags can begin with a lowercase letter.
2221
2221
```jsx harmony
2222
2222
classSomeComponentextendsComponent {
2223
2223
// Code goes here
@@ -2244,8 +2244,8 @@ You can download the PDF and Epub version of this repository from the latest run
2244
2244
2245
2245
#### What are the exceptions on React component naming?
2246
2246
2247
-
The component names should start with a uppercase letter but there are few exceptions on this convention. The lowercase tag names with a dot (property accessors) are still considered as valid component names.
2248
-
For example the below tag can be compiled to a valid component,
2247
+
The component names should start with an uppercase letter but there are few exceptions to this convention. The lowercase tag names with a dot (property accessors) are still considered as valid component names.
2248
+
For example, the below tag can be compiled to a valid component,
2249
2249
2250
2250
```jsx harmony
2251
2251
render() {
@@ -4741,7 +4741,7 @@ You can download the PDF and Epub version of this repository from the latest run
4741
4741
4742
4742
216. ### What is render hijacking in react?
4743
4743
4744
-
The concept of render hijacking is the ability to control what a component will output from another component. It actually means that you decorate your component by wrapping it into a Higher-Order component. By wrapping you can inject additional props or make other changes, which can cause changing logic of rendering. It does not actually enables hijacking, but by using HOC you make your component behave in different way.
4744
+
The concept of render hijacking is the ability to control what a component will output from another component. It means that you decorate your component by wrapping it into a Higher-Order component. By wrapping, you can inject additional props or make other changes, which can cause changing logic of rendering. It does not actually enable hijacking, but by using HOC you make your component behave differently.
4745
4745
4746
4746
4747
4747
**[⬆ Back to Top](#table-of-contents)**
@@ -4795,7 +4795,7 @@ You can download the PDF and Epub version of this repository from the latest run
4795
4795
**[⬆ Back to Top](#table-of-contents)**
4796
4796
4797
4797
219. ### Do I need to keep all my state into Redux? Should I ever use react internal state?
4798
-
It is up to developer decision. i.e, It is developer job to determine what kinds of state make up your application, and where each piece of state should live. Some users prefer to keep every single piece of data in Redux, to maintain a fully serializable and controlled version of their application at all times. Others prefer to keep non-critical or UI state, such as “is this dropdown currently open”, inside a component's internal state.
4798
+
It is up to the developer's decision,i.e., it is developer's job to determine what kinds of state make up your application, and where each piece of state should live. Some users prefer to keep every single piece of data in Redux, to maintain a fully serializable and controlled version of their application at all times. Others prefer to keep non-critical or UI state, such as “is this dropdown currently open”, inside a component's internal state.
4799
4799
4800
4800
Below are the thumb rules to determine what kind of data should be put into Redux
4801
4801
1. Do other parts of the application care about this data?
@@ -4809,7 +4809,7 @@ You can download the PDF and Epub version of this repository from the latest run
4809
4809
4810
4810
220. ### What is the purpose of registerServiceWorker in React?
4811
4811
4812
-
React creates a service worker for you without any configuration by default. The service worker is a web API that helps you cache your assets and other files so that when the user is offline or on slow network, he/she can still see results on the screen, as such, it helps you build a better user experience, that's what you should know about service worker'sfornow. It's all about adding offline capabilities to your site.
4812
+
React creates a service worker for you without any configuration by default. The service worker is a web API that helps you cache your assets and other files so that when the user is offline or on a slow network, he/she can still see results on the screen, as such, it helps you build a better user experience, that's what you should know about service worker for now. It's all about adding offline capabilities to your site.
4813
4813
4814
4814
```jsx
4815
4815
import React from 'react';
@@ -4853,7 +4853,7 @@ You can download the PDF and Epub version of this repository from the latest run
4853
4853
**[⬆ Back to Top](#table-of-contents)**
4854
4854
4855
4855
223. ### How to prevent unnecessary updates using setState?
4856
-
You can compare current value of the state with an existing state value and decide whether to rerender the page or not. If the values are same then you need to return **null** to stop re-rendering otherwise return the latest state value.
4856
+
You can compare the current value of the state with an existing state value and decide whether to rerender the page or not. If the values are the same then you need to return **null** to stop re-rendering otherwise return the latest state value.
4857
4857
4858
4858
For example, the user profile information is conditionally rendered as follows,
4859
4859
```jsx
@@ -4913,7 +4913,7 @@ You can download the PDF and Epub version of this repository from the latest run
4913
4913
**[⬆ Back to Top](#table-of-contents)**
4914
4914
4915
4915
225. ### How to use class field declarations syntax in React classes?
4916
-
React Class Components can be made much more concise using the classfielddeclarations. You can initialize local state without using the constructor and declare class methods by using arrow functions without the extra need to bind them.
4916
+
React Class Components can be made much more concise using the class field declarations. You can initialize the local state without using the constructor and declare class methods by using arrow functions without the extra need to bind them.
4917
4917
4918
4918
Let's take a counter example to demonstrate class field declarations for state without using constructor and methods without binding,
4919
4919
```jsx
@@ -5725,8 +5725,8 @@ You can download the PDF and Epub version of this repository from the latest run
5725
5725
**[⬆ Back to Top](#table-of-contents)**
5726
5726
5727
5727
271. ### Why are you not required to use inheritance?
5728
-
In React, it is recommended to use composition over inheritance to reuse code between components. Both Props and composition give you all the flexibility you need to customize a component’s look and behavior in an explicit and safe way.
5729
-
Whereas, If you want to reuse non-UI functionality between components, it is suggested to extracting it into a separate JavaScript module. Later components import it and use that function, object, or a class, without extending it.
5728
+
In React, it is recommended to use composition over inheritance to reuse code between components. Both Props and composition give you all the flexibility you need to customize a component’s look and behavior explicitly and safely.
5729
+
Whereas, If you want to reuse non-UI functionality between components, it is suggested to extract it into a separate JavaScript module. Later components import it and use that function, object, or class, without extending it.
5730
5730
5731
5731
**[⬆ Back to Top](#table-of-contents)**
5732
5732
@@ -6029,7 +6029,7 @@ You can download the PDF and Epub version of this repository from the latest run
6029
6029
exportdefaultlogProps(FancyButton);
6030
6030
```
6031
6031
6032
-
Now lets create a ref and pass it to FancyButton component. In this case, you can set focus to button element.
6032
+
Now let's create a ref and pass it to FancyButton component. In this case, you can set focus to button element.
6033
6033
6034
6034
```javascript
6035
6035
importFancyButtonfrom'./FancyButton';
@@ -6118,7 +6118,7 @@ You can download the PDF and Epub version of this repository from the latest run
6118
6118
287. ### What is diffing algorithm?
6119
6119
React needs to use algorithms to find out how to efficiently update the UI to match the most recent tree. The diffing algorithms is generating the minimum number of operations to transform one tree into another. However, the algorithms have a complexity in the order of O(n3) where n is the number of elements in the tree.
6120
6120
6121
-
In this case, for displaying 1000 elements would require in the order of one billion comparisons. This is far too expensive. Instead, React implements a heuristic O(n) algorithm based on two assumptions:
6121
+
In this case, displaying 1000 elements would require in the order of one billion comparisons. This is far too expensive. Instead, React implements a heuristic O(n) algorithm based on two assumptions:
6122
6122
6123
6123
1. Two elements of different types will produce different trees.
6124
6124
2. The developer can hint at which child elements may be stable across different renders with a key prop.
@@ -6806,13 +6806,13 @@ ReactDOM.render(
6806
6806
6807
6807
```
6808
6808
6809
-
**How to prevent it:** Make sure your state variables are immutable by either enforcing immutability by using plugins like Immutable.js, always using `setState` to make updates and returning new instances in reducers when sending updated state values.
6809
+
**How to prevent it:** Make sure your state variables are immutable by either enforcing immutability by using plugins like Immutable.js, always using `setState` to make updates, and returning new instances in reducers when sending updated state values.
6810
6810
6811
6811
**[⬆ Back to Top](#table-of-contents)**
6812
6812
6813
6813
332. ### What is the difference between useState and useRef hook?
6814
6814
1. useState causes components to re-render after state updates whereas useRef doesn’t cause a component to re-render when the value or state changes.
6815
6815
Essentially, useRef is like a “box” that can hold a mutable value in its (.current) property.
6816
-
2. useState allows us to update the state inside components. While useRef allows to reference DOM elements.
6816
+
2. useState allows us to update the state inside components. While useRef allows refrencing DOM elements.
0 commit comments