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
- the function is used by a non-presentational component. Presentational components are simple components that are either plain MUI components, or components that compose multiple MUI component with NO additional complex logic.
8
+
9
+
Hi, I want you to help me start optimizing my components. I plan to properly memoize my components using useCallback, useMemo and memo.
10
+
Please optimize all components in this directory (and all sub-directories) frontend/src/components/Memo/ according to the following guidelines:
11
+
12
+
Functions:
13
+
I want you to memoize all functions with useCallback. If there are any inline function definitions (in the rendering part), please create a new callback function for this.
14
+
15
+
Components:
16
+
If possible, try to memoize the component itself using memo. All my components should be normal functions and exported default at the bottom. If you think the component can be memoized with memo(), wrap the export default!
17
+
If there are multiple components defined inside a file, still, only wrap the component that is exported.
18
+
If the component is a very basic presentational component, there is no need to memoize it.
19
+
20
+
Mutations:
21
+
Sometimes, I am using react query mutations. Beware! The mutation is not a stable reference and should not used in dependency arrays of useCallbacks. We need to destructure the mutation like that {mutate: functionName, isPending } = useMyMutation(). The functionName is now a stable reference that can be used
22
+
23
+
Computed variables:
24
+
In case you see any variables that are a result of heavy computation, please consider using useMemo.
25
+
26
+
Rendering:
27
+
By default, please do not useMemo to memoize components that are rendered. Instead, first see if we can optimize the rendered component.
28
+
Only as a last resort, memoize the component with useMemo.
29
+
30
+
Comments:
31
+
Keep all my comments! Never delete my comments! You may add new comments if you think that is necessary, but DO NOT delete my comments.
32
+
33
+
General Guidelines:
34
+
35
+
- DO NOT rename existing variables, functions, components, except if they have typos!
36
+
- only optimize Components, do not optimize hooks
37
+
- DO NOT move (sub-)components inside a file, the order is fine!
38
+
39
+
Sometimes, the component is already optimized. Then, you can simply skip it!
* The IDs, scores and (optional) highlights of Document search results on the requested page.
10
+
*/
11
+
hits: Array<ElasticSearchDocumentHit>;
12
+
/**
13
+
* A dictionary with the additional information about the documents. The key is the document ID and the value is a dictionary with the additional information.
14
+
*/
15
+
sdocs: Record<string,SourceDocumentRead>;
16
+
/**
17
+
* A dictionary with the additional information about the documents. The key is the document ID and the value is a dictionary with the additional information.
18
+
*/
19
+
annotators: Record<string,Array<number>>;
20
+
/**
21
+
* A dictionary with the additional information about the documents. The key is the document ID and the value is a dictionary with the additional information.
"description": "A dictionary with the additional information about the documents. The key is the document ID and the value is a dictionary with the additional information."
"description": "A dictionary with the additional information about the documents. The key is the document ID and the value is a dictionary with the additional information."
"description": "A dictionary with the additional information about the documents. The key is the document ID and the value is a dictionary with the additional information."
8117
+
},
8118
+
"total_results": {
8119
+
"type": "integer",
8120
+
"title": "Total Results",
8121
+
"description": "The total number of hits. Used for pagination."
0 commit comments