From 6ebafbfaf92df1680914bc672297f7a2fffc9205 Mon Sep 17 00:00:00 2001 From: Luck Date: Fri, 21 May 2021 17:37:56 +0100 Subject: [PATCH] refactor reduce func to prevent stack overflows --- src/components/EditorTextArea.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/components/EditorTextArea.js b/src/components/EditorTextArea.js index bc2fa07..01394df 100644 --- a/src/components/EditorTextArea.js +++ b/src/components/EditorTextArea.js @@ -21,7 +21,13 @@ export default function EditorTextArea({ code, setCode, language, fontSize }) { )) - .reduce((prev, curr) => [prev, '\n', curr]); + .reduce((acc, curr, idx) => { + if (idx !== 0) { + acc.push('\n'); + } + acc.push(curr); + return acc; + }, []); } const autoBracketState = useState(null);