Skip to content

Commit

Permalink
Replace useEffect with useEffectOnce
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulyadav-57 committed Sep 18, 2023
1 parent b8247be commit 1f554bf
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
8 changes: 5 additions & 3 deletions src/components/shared/LogView/LogView.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { LogType } from '@/interfaces/log.interface';
import EventEmitter from '@/utility/eventEmitter';
import { FC, createRef, useEffect, useRef } from 'react';
import { FC, createRef, useRef } from 'react';
import { useEffectOnce } from 'react-use';

import 'xterm/css/xterm.css';

import s from './LogView.module.scss';
Expand Down Expand Up @@ -29,7 +31,7 @@ const LogView: FC<Props> = ({ type, text }) => {
reset: '\x1b[0m',
};

useEffect(() => {
useEffectOnce(() => {
let terminal: any | null = null;

const initTerminal = async () => {
Expand Down Expand Up @@ -88,7 +90,7 @@ const LogView: FC<Props> = ({ type, text }) => {
EventEmitter.off('LOG_CLEAR');
terminal?.dispose();
};
}, []);
});

return <div className={s.root} ref={logViewerRef} id="app-terminal"></div>;
};
Expand Down
17 changes: 10 additions & 7 deletions src/components/workspace/BottomPanel/BottomPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { useLogActivity } from '@/hooks/logActivity.hooks';
import { LogOptions, LogType } from '@/interfaces/log.interface';
import { debounce } from '@/utility/utils';
import { Tooltip } from 'antd';
import { FC, useEffect, useState } from 'react';
import { FC, useState } from 'react';
import { useEffectOnce } from 'react-use';
import s from './BottomPanel.module.scss';

type logType = LogType | 'all';
Expand Down Expand Up @@ -41,9 +42,9 @@ const BottomPanel: FC = () => {
setFilter({ text: searchTerm, type: filter.type });
}, 200);

useEffect(() => {
useEffectOnce(() => {
setIsLoaded(true);
}, []);
});

return (
<div className={s.root}>
Expand All @@ -69,10 +70,12 @@ const BottomPanel: FC = () => {
</div>
</div>
<div className={s.view}>
<LogView
text={filter?.text || undefined}
type={filter.type !== 'all' ? filter.type : undefined}
/>
{isLoaded && (
<LogView
text={filter?.text || undefined}
type={filter.type !== 'all' ? filter.type : undefined}
/>
)}
</div>
</div>
);
Expand Down
6 changes: 5 additions & 1 deletion src/components/workspace/WorkSpace/WorkSpace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Blockchain } from '@ton-community/sandbox';
import { Spin } from 'antd';
import { useRouter } from 'next/router';
import { FC, useEffect, useState } from 'react';
import { useEffectOnce } from 'react-use';
import BottomPanel from '../BottomPanel/BottomPanel';
import BuildProject from '../BuildProject';
import Editor from '../Editor';
Expand Down Expand Up @@ -96,9 +97,12 @@ const WorkSpace: FC = () => {
if (tab) {
setActiveMenu(tab as WorkSpaceMenu);
}
setIsLoaded(true);
}, [tab]);

useEffectOnce(() => {
setIsLoaded(true);
});

return (
<div className={`${s.root} show-file-icons`}>
<div className={`${s.sidebar} onboarding-workspace-sidebar`}>
Expand Down

0 comments on commit 1f554bf

Please sign in to comment.