8000 fix: hooks violation · Aidurber/react-picky@f109d37 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Jan 15, 2021. It is now read-only.

Commit f109d37

Browse files
committed
fix: hooks violation
1 parent c66c6fc commit f109d37

File tree

1 file changed

+25
-32
lines changed

1 file changed

+25
-32
lines changed

src/SelectAll.tsx

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,31 @@ type SelectAllProps = {
1010
toggleSelectAll(): void;
1111
visible: boolean;
1212
};
13-
const SelectAll: React.FC<SelectAllProps> = React.memo(
14-
({
15-
tabIndex,
16-
disabled,
17-
allSelected,
18-
id,
19-
selectAllText,
20-
toggleSelectAll,
21-
visible,
22-
}) => {
23-
const checkboxRef = React.useRef<HTMLInputElement>();
2413

25-
React.useEffect(() => {
26-
if (checkboxRef.current) {
27-
checkboxRef.current.indeterminate = allSelected === 'partial';
14+
class SelectAll extends React.PureComponent<SelectAllProps> {
15+
static displayName = 'Picky(SelectAll)';
16+
checkboxRef = React.createRef<HTMLInputElement>();
17+
18+
componentDidUpdate(prevProps: SelectAllProps) {
19+
if (prevProps.allSelected !== this.props.allSelected) {
20+
if (this.checkboxRef && this.checkboxRef.current) {
21+
this.checkboxRef.current.indeterminate =
22+
this.props.allSelected === 'partial';
2823
}
29-
}, [allSelected]);
30-
if (!visible) {
31-
return null;
3224
}
25+
}
26+
render() {
27+
const {
28+
tabIndex,
29+
disabled,
30+
allSelected,
31+
id,
32+
selectAllText,
33+
toggleSelectAll,
34+
visible,
35+
} = this.props;
36+
37+
if (!visible) return null;
3338
return (
3439
<div
3540
tabIndex={tabIndex}
@@ -44,7 +49,7 @@ const SelectAll: React.FC<SelectAllProps> = React.memo(
4449
>
4550
<input
4651
type="checkbox"
47-
ref={checkboxRef}
52+
ref={this.checkboxRef}
4853
readOnly
4954
data-testid="selectall-checkbox"
5055
tabIndex={-1}
@@ -55,19 +60,7 @@ const SelectAll: React.FC<SelectAllProps> = React.memo(
5560
<span data-testid="select-all-text">{selectAllText}</span>
5661
</div>
5762
);
58-
},
59-
areEqual
60-
);
61-
62-
SelectAll.displayName = 'Picky(SelectAll)';
63-
64-
function areEqual(prevProps: SelectAllProps, nextProps: SelectAllProps) {
65-
return (
66-
prevProps.tabIndex === nextProps.tabIndex &&
67-
prevProps.disabled === nextProps.disabled &&
68-
prevProps.allSelected === nextProps.allSelected &&
69-
prevProps.selectAllText === nextProps.selectAllText &&
70-
prevProps.visible === nextProps.visible
71-
);
63+
}
7264
}
65+
7366
export { SelectAll };

0 commit comments

Comments
 (0)
0