wrap some more callbacks in useCallback

This commit is contained in:
Joeri Exelmans 2025-10-23 22:10:18 +02:00
parent 87ceaa1220
commit 529ad1d4bd

View file

@ -92,14 +92,14 @@ export function App() {
const refRightSideBar = useRef<HTMLDivElement>(null); const refRightSideBar = useRef<HTMLDivElement>(null);
// append editor state to undo history // append editor state to undo history
function makeCheckPoint() { const makeCheckPoint = useCallback(() => {
setHistoryState(historyState => ({ setHistoryState(historyState => ({
...historyState, ...historyState,
history: [...historyState.history, historyState.current], history: [...historyState.history, historyState.current],
future: [], future: [],
})); }));
} }, [setHistoryState]);
function onUndo() { const onUndo = useCallback(() => {
setHistoryState(historyState => { setHistoryState(historyState => {
if (historyState.history.length === 0) { if (historyState.history.length === 0) {
return historyState; // no change return historyState; // no change
@ -110,8 +110,8 @@ export function App() {
future: [...historyState.future, historyState.current], future: [...historyState.future, historyState.current],
} }
}) })
} }, [setHistoryState]);
function onRedo() { const onRedo = useCallback(() => {
setHistoryState(historyState => { setHistoryState(historyState => {
if (historyState.future.length === 0) { if (historyState.future.length === 0) {
return historyState; // no change return historyState; // no change
@ -122,7 +122,7 @@ export function App() {
future: historyState.future.slice(0,-1), future: historyState.future.slice(0,-1),
} }
}); });
} }, [setHistoryState]);
function onInit() { function onInit() {
const timestampedEvent = {simtime: 0, inputEvent: "<init>"}; const timestampedEvent = {simtime: 0, inputEvent: "<init>"};
@ -144,11 +144,10 @@ export function App() {
setTime({kind: "paused", simtime: 0}); setTime({kind: "paused", simtime: 0});
scrollDownSidebar(); scrollDownSidebar();
} }
const onClear = useCallback(() => {
function onClear() {
setTrace(null); setTrace(null);
setTime({kind: "paused", simtime: 0}); setTime({kind: "paused", simtime: 0});
} }, [setTrace, setTime]);
// raise input event, producing a new runtime configuration (or a runtime error) // raise input event, producing a new runtime configuration (or a runtime error)
function onRaise(inputEvent: string, param: any) { function onRaise(inputEvent: string, param: any) {
@ -225,7 +224,6 @@ export function App() {
scrollDownSidebar(); scrollDownSidebar();
} }
function onBack() { function onBack() {
if (trace !== null) { if (trace !== null) {
setTime(() => { setTime(() => {
@ -244,7 +242,7 @@ export function App() {
} }
} }
function scrollDownSidebar() { const scrollDownSidebar = useCallback(() => {
if (refRightSideBar.current) { if (refRightSideBar.current) {
const el = refRightSideBar.current; const el = refRightSideBar.current;
// hack: we want to scroll to the new element, but we have to wait until it is rendered... // hack: we want to scroll to the new element, but we have to wait until it is rendered...
@ -252,7 +250,7 @@ export function App() {
el.scrollIntoView({block: "end", behavior: "smooth"}); el.scrollIntoView({block: "end", behavior: "smooth"});
}, 50); }, 50);
} }
} }, []);
useEffect(() => { useEffect(() => {
console.log("Welcome to StateBuddy!"); console.log("Welcome to StateBuddy!");