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: lib/components/SearchBar.js
+14-1Lines changed: 14 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@ import React from 'react';
2
2
importdebouncefrom'lodash.debounce';//NOTE: we are just importing the debounce function from lodash not the whole package
3
3
importstoreProviderfrom'./storeProvider';
4
4
5
-
classSearchBarextendsReact.Component{
5
+
classSearchBarextendsReact.PureComponent{
6
6
7
7
state={
8
8
searchTerm: ''
@@ -21,6 +21,19 @@ class SearchBar extends React.Component{
21
21
22
22
};
23
23
24
+
//In this case we can just convert this to a PureComponent which does the job described below for us.
25
+
// shouldComponentUpdate(nextProps, nextState){
26
+
// //if we just pass FALSE it will render but does not allow us to type anything as the component is not connected with teh tree
27
+
// //return false;
28
+
// //If we pass TRUE it will rerender everysecons as our state with the tick interval is updating the state and a normal component re-renders every time the state is updated.
29
+
// //return true;
30
+
// //To solve the issue we should compare current and next props as well as current and previosu state
31
+
// }
32
+
33
+
componentWillUpdate(nextProps,nextState)
34
+
{
35
+
console.log('Updating SearchBar');
36
+
}
24
37
25
38
//Option 1. We could read the value of the text typed by ref (getting the current DOM node)
0 commit comments