Skip to content

Commit f783186

Browse files
committed
Revert hooks version of WorkspaceItem for now
Some shouldComponentUpdate logic is omitted in the conversion, which seems crucial for updating the component
1 parent 9d553db commit f783186

File tree

1 file changed

+30
-19
lines changed
  • packages/app/src/app/pages/Sandbox/Editor/Workspace/WorkspaceItem

1 file changed

+30
-19
lines changed
Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState } from 'react';
1+
import React from 'react';
22
import { Animate as ReactShow } from 'react-show';
33

44
import {
@@ -11,42 +11,55 @@ import {
1111

1212
type Props = {
1313
children: React.ReactNode;
14-
title: string | React.ReactElement<any>;
14+
title: string;
1515
keepState?: boolean;
1616
disabled?: boolean;
1717
defaultOpen?: boolean;
1818
actions?: React.Component<any, any>;
1919
style?: React.CSSProperties;
2020
};
2121

22-
const WorkspaceItem = React.memo(
23-
({
24-
children,
25-
title,
26-
keepState,
27-
disabled,
28-
actions,
29-
style,
30-
defaultOpen = false,
31-
}: Props) => {
32-
const [open, setOpen] = useState(defaultOpen);
22+
type State = {
23+
open: boolean;
24+
};
25+
26+
export default class WorkspaceItem extends React.Component<Props, State> {
27+
constructor(props: Props) {
28+
super(props);
29+
this.state = {
30+
open: Boolean(props.defaultOpen),
31+
};
32+
}
33+
34+
shouldComponentUpdate(nextProps: Props, nextState: State) {
35+
return (
36+
nextState.open !== this.state.open ||
37+
nextProps.disabled !== this.props.disabled ||
38+
this.props.children !== nextProps.children
39+
);
40+
}
41+
42+
toggleOpen = () => this.setState({ open: !this.state.open });
43+
44+
render() {
45+
const { children, title, keepState, disabled, actions, style } = this.props;
46+
const { open } = this.state;
3347

3448
return (
3549
<>
36-
<ItemHeader style={style} onClick={() => setOpen(!open)}>
50+
<ItemHeader style={style} onClick={this.toggleOpen}>
3751
<ExpandIconContainer open={open} />
3852
<Title>{title}</Title>
3953

4054
{open && <Actions>{actions}</Actions>}
4155
</ItemHeader>
4256
<ReactShow
4357
style={{
44-
overflow: 'visible',
4558
height: 'auto',
59+
overflow: 'hidden',
4660
}}
4761
transitionOnMount
4862
start={{
49-
overflow: 'hidden',
5063
height: 0, // The starting style for the component.
5164
// If the 'leave' prop isn't defined, 'start' is reused!
5265
}}
@@ -59,6 +72,4 @@ const WorkspaceItem = React.memo(
5972
</>
6073
);
6174
}
62-
);
63-
64-
export default WorkspaceItem;
75+
}

0 commit comments

Comments
 (0)