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
+8-8Lines changed: 8 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -513,15 +513,15 @@ You can download the PDF and Epub version of this repository from the latest run
513
513
6. ### When to use a Class Component over a Function Component?
514
514
515
515
If the component needs _state or lifecycle methods_ then use classcomponent otherwise use function component.
516
-
516
+
517
517
_However, from React 16.8 with the addition of Hooks, you could use state , lifecycle methods and other features that were only available in class component right in your function component._
518
518
_So, it is always recommended to use Function components, unless you need a React functionality whose Function component equivalent is not present yet, like Error Boundaries._
519
519
520
520
**[⬆ Back to Top](#table-of-contents)**
521
521
522
522
7. ### What are Pure Components?
523
523
524
-
_`React.PureComponent`_ is exactly the same as _`React.Component`_ except that it handles the `shouldComponentUpdate()` method for you. When props or state changes, _PureComponent_ will do a shallow comparison on both props and state. _Component_ on the other hand won't compare current props and state to next out of the box. Thus, the component will re-render by default whenever `shouldComponentUpdate` is called. In functional componenets we use `React.memo()` API. `React.memo()` is a higher-order component. It takes a React component as its first argument and returns a special type of React component that allows the renderer to render the component while memoizing the output. Therefore, if the component’s props are shallowly equal, the `React.memo()` component will bail out the updates.
524
+
_`React.PureComponent`_ is exactly the same as _`React.Component`_ except that it handles the `shouldComponentUpdate()` method for you. When props or state changes, _PureComponent_ will do a shallow comparison on both props and state. _Component_ on the other hand won't compare current props and state to next out of the box. Thus, the component will re-render by default whenever `shouldComponentUpdate` is called. In functional components we use `React.memo()` API. `React.memo()` is a higher-order component. It takes a React component as its first argument and returns a special type of React component that allows the renderer to render the component while memoizing the output. Therefore, if the component’s props are shallowly equal, the `React.memo()` component will bail out the updates.
525
525
526
526
**[⬆ Back to Top](#table-of-contents)**
527
527
@@ -4319,9 +4319,9 @@ You can download the PDF and Epub version of this repository from the latest run
332. ### What is the difference between useState and useRef hook?
6869
6869
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.
6870
6870
Essentially, useRef is like a “box” that can hold a mutable value in its (.current) property.
6871
-
2. useState allows us to update the state inside components. While useRef allows refrencing DOM elements.
6871
+
2. useState allows us to update the state inside components. While useRef allows referencing DOM elements.
6872
6872
6873
6873
**[⬆ Back to Top](#table-of-contents)**
6874
6874
@@ -6956,7 +6956,7 @@ function App() {
6956
6956
```
6957
6957
6958
6958
<h4> Props in Class Component</h4>
6959
-
Props are referred to as "properties". props are passed into react component just like arguments are passed into functions . Props are being specified as attribute just like your html. for example if the name attribute is "name " we assign a value to name. so basically, props are object that contains an attribute and its corresponding value. Data can be passed from parent component to the children component, but this data is immutable, which means that we cannot modify the props across another component. here is an example
6959
+
Props are referred to as "properties". props are passed into react component just like arguments are passed into functions . Props are being specified as attribute just like your html. for example if the name attribute is "name " we assign a value to name. so basically, props are object that contains an attribute and its corresponding value. Data can be passed from parent component to the children component, but this data is immutable, which means that we cannot modify the props across another component. here is an example
0 commit comments