Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8178b92

Browse files
committed
edit cleanup functions, dispatchConsoleEvent in ConsoleInput
1 parent 54903cb commit 8178b92

File tree

2 files changed

+9
-18
lines changed

2 files changed

+9
-18
lines changed

client/modules/IDE/components/Console.jsx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,11 @@ const Console = () => {
3838
const handleMessageEvent = useHandleMessageEvent();
3939

4040
useEffect(() => {
41-
listen(handleMessageEvent);
42-
}, [handleMessageEvent]);
41+
const unsubscribe = listen(handleMessageEvent);
42+
return function cleanup() {
43+
unsubscribe();
44+
};
45+
});
4346

4447
const handleClearConsole = () => dispatch(ConsoleActions.clearConsole());
4548
const handleCollapseConsole = () => dispatch(IDEActions.collapseConsole());
@@ -92,13 +95,7 @@ const Console = () => {
9295
/>
9396
</div>
9497
{isExpanded && isPlaying && (
95-
<ConsoleInput
96-
theme={theme}
97-
dispatchConsoleEvent={(event) =>
98-
dispatch(ConsoleActions.dispatchConsoleEvent(event))
99-
}
100-
fontSize={fontSize}
101-
/>
98+
<ConsoleInput theme={theme} fontSize={fontSize} />
10299
)}
103100
</div>
104101
</section>

client/modules/IDE/components/ConsoleInput.jsx

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ import CodeMirror from 'codemirror';
44
import { Encode } from 'console-feed';
55

66
import RightArrowIcon from '../../../images/right-arrow.svg';
7+
import { dispatchConsoleEvent } from '../../IDE/actions/console';
78
import { dispatchMessage, MessageTypes } from '../../../utils/dispatcher';
89

910
// heavily inspired by
1011
// https://github.com/codesandbox/codesandbox-client/blob/92a1131f4ded6f7d9c16945dc7c18aa97c8ada27/packages/app/src/app/components/Preview/DevTools/Console/Input/index.tsx
1112

12-
function ConsoleInput({ theme, dispatchConsoleEvent, fontSize }) {
13+
function ConsoleInput({ theme, fontSize }) {
1314
const [commandHistory, setCommandHistory] = useState([]);
1415
const [commandCursor, setCommandCursor] = useState(-1);
1516
const codemirrorContainer = useRef(null);
@@ -25,12 +26,6 @@ function ConsoleInput({ theme, dispatchConsoleEvent, fontSize }) {
2526
});
2627

2728
cmInstance.current.getWrapperElement().style['font-size'] = `${fontSize}px`;
28-
29-
return () => {
30-
if (cmInstance.current) {
31-
cmInstance.current = null;
32-
}
33-
};
3429
}, []);
3530

3631
useEffect(() => {
@@ -78,7 +73,7 @@ function ConsoleInput({ theme, dispatchConsoleEvent, fontSize }) {
7873
cmInstance.current.off('keydown', handleEnterKey);
7974
}
8075
};
81-
}, [commandHistory, dispatchConsoleEvent]);
76+
}, [commandHistory]);
8277

8378
useEffect(() => {
8479
const handleUpArrowKey = (cm, e) => {
@@ -158,7 +153,6 @@ function ConsoleInput({ theme, dispatchConsoleEvent, fontSize }) {
158153

159154
ConsoleInput.propTypes = {
160155
theme: PropTypes.string.isRequired,
161-
dispatchConsoleEvent: PropTypes.func.isRequired,
162156
fontSize: PropTypes.number.isRequired
163157
};
164158

0 commit comments

Comments
 (0)