Skip to content

Commit 4e16bca

Browse files
committed
Add local storage persistency
1 parent d9ab3c0 commit 4e16bca

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/index.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,18 @@ const Terminal = ({
177177
}
178178
}, [historyIndex, history.length]);
179179

180+
// history local storage persistency
181+
useEffect(() => {
182+
const storedHistory = localStorage.getItem("terminal-history");
183+
if (storedHistory) {
184+
setHistory(JSON.parse(storedHistory));
185+
}
186+
}, []);
187+
188+
useEffect(() => {
189+
localStorage.setItem("terminalhistory", JSON.stringify(history));
190+
}, [history]);
191+
180192
// We use a hidden input to capture terminal input; make sure the hidden input is focused when clicking anywhere on the terminal
181193
useEffect(() => {
182194
if (onInput == null) {

0 commit comments

Comments
 (0)