Skip to content

Commit 2f30fd0

Browse files
committed
Fet rid of some effects
1 parent 7b69367 commit 2f30fd0

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

src/index.tsx

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,19 @@ interface AppProps {
3434
const defaultSource = tutorial;
3535

3636
const SOURCE_SAVE_TIMEOUT = 5 * 1000; // 5 seconds
37+
type Timeout = ReturnType<typeof setTimeout>;
38+
39+
const saver = new FileSaver();
3740

3841
function App({ initialText, initialEngine }: AppProps) {
3942
const [engine, setEngine] = useState<SupportedEngine>(
4043
initialEngine ?? defaultEngine,
4144
);
4245

4346
const currentSourceRef = useRef<string | undefined>(undefined);
44-
const saverRef = useRef<FileSaver>(new FileSaver());
45-
const editorRef: RefObject<
46-
import("./components/SplitEditor").default | null
47-
> = useRef(null);
48-
const autoSaveTimeoutRef = useRef<ReturnType<typeof setTimeout> | undefined>(
49-
undefined,
50-
);
47+
const editorRef: RefObject<SplitEditor | null> = useRef(null);
48+
const autoSaveTimeoutRef = useRef<Timeout | undefined>(undefined);
49+
const initialSource = initialText ? initialText : defaultSource;
5150

5251
useEffect(() => {
5352
return () => {
@@ -57,7 +56,6 @@ function App({ initialText, initialEngine }: AppProps) {
5756
};
5857
}, []);
5958

60-
const initialSource = initialText ? initialText : defaultSource;
6159
return (
6260
<div className="main-container">
6361
<Navigation
@@ -70,9 +68,9 @@ function App({ initialText, initialEngine }: AppProps) {
7068
const dotSrc = currentSourceRef.current;
7169
if (dotSrc) {
7270
if (format === sourceFormatExtension) {
73-
saveSource(dotSrc, saverRef.current);
71+
saveSource(dotSrc, saver);
7472
} else {
75-
exportAs(dotSrc, format, { engine }, saverRef.current);
73+
exportAs(dotSrc, format, { engine }, saver);
7674
}
7775
}
7876
}}

0 commit comments

Comments
 (0)