Skip to content

Commit 49570d4

Browse files
committed
Just an idea / me going all #microperf here
#79749 (comment)
1 parent a30f8d5 commit 49570d4

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
jest.mock('react', () => ({
8+
...(jest.requireActual('react') as object),
9+
useMemo: jest.fn((fn) => fn()), // Calls on mount/every update - use mount for more complex behavior
10+
}));
11+
12+
/**
13+
* Example usage within a component test using shallow():
14+
*
15+
* import '../../../__mocks__/shallow_usememo.mock'; // Must come before React's import, adjust relative path as needed
16+
*
17+
* import React from 'react';
18+
* import { shallow } from 'enzyme';
19+
*
20+
* // ... etc.
21+
*/

x-pack/plugins/enterprise_search/public/applications/app_search/components/credentials/credentials_list/credentials_list.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import React from 'react';
7+
import React, { useMemo } from 'react';
88
import { EuiBasicTable, EuiBasicTableColumn, EuiButtonIcon, EuiCopy } from '@elastic/eui';
99
import { CriteriaWithPagination } from '@elastic/eui/src/components/basic_table/basic_table';
1010
import { useActions, useValues } from 'kea';
@@ -22,7 +22,7 @@ export const CredentialsList: React.FC = () => {
2222

2323
const { apiTokens, meta } = useValues(CredentialsLogic);
2424

25-
const items = apiTokens.slice().sort(apiTokenSort);
25+
const items = useMemo(() => apiTokens.slice().sort(apiTokenSort), [apiTokens]);
2626

2727
const columns: Array<EuiBasicTableColumn<IApiToken>> = [
2828
{

0 commit comments

Comments
 (0)