Skip to content

Commit 27bf8ca

Browse files
fix(@clayui/core): fixes bug when updating the state at render time and the number of table columns when the state changes
1 parent f7997ff commit 27bf8ca

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

packages/clay-core/src/table/Head.tsx

+7-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import Button from '@clayui/button';
77
import {ClayToggle as Toggle} from '@clayui/form';
88
import Icon from '@clayui/icon';
99
import Layout from '@clayui/layout';
10-
import React, {useMemo} from 'react';
10+
import React, {useEffect, useLayoutEffect} from 'react';
1111

1212
import {ChildrenFunction, Collection, useCollection} from '../collection';
1313
import {Item, Menu} from '../drop-down';
@@ -36,6 +36,9 @@ const Header = React.forwardRef<HTMLLIElement, HeaderProps>(
3636
}
3737
);
3838

39+
const useIsomorphicEffect =
40+
typeof window === 'undefined' ? useEffect : useLayoutEffect;
41+
3942
type Props<T> = {
4043
/**
4144
* Children content to render a dynamic or static content.
@@ -68,12 +71,13 @@ function HeadInner<T extends Record<string, any>>(
6871
visibleKeys: new Set(visibleColumns.keys()),
6972
});
7073

71-
useMemo(() => {
74+
useIsomorphicEffect(() => {
75+
console.log('test');
7276
if (visibleColumns.size === 0) {
7377
onVisibleColumnsChange(collection.getItems(), 0);
7478
}
7579
onHeadCellsChange(collection.getSize());
76-
}, []);
80+
}, [collection.getSize()]);
7781

7882
return (
7983
<thead {...otherProps} ref={ref}>

0 commit comments

Comments
 (0)