Skip to content

Commit

Permalink
chore: useMemo instead of useState
Browse files Browse the repository at this point in the history
  • Loading branch information
cazala committed Nov 11, 2024
1 parent 7240c22 commit 9ed2bf9
Showing 1 changed file with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useCallback, useState } from 'react';
import { useCallback, useMemo, useState } from 'react';
import { Initial } from './steps/Initial';
import { AlternativeServers } from './steps/AlternativeServers';
import { PublishToWorld } from './steps/PublishToWorld';
Expand All @@ -8,27 +8,26 @@ import { Deploy } from './steps/Deploy';
import type { Props, Step } from './types';

export function PublishProject({ open, project, onClose }: Omit<Props, 'onStep'>) {
const [step, setStep] = useState<Step>('initial');
const [history, setHistory] = useState<Step[]>([]);
const step = useMemo<Step>(
() => (history.length > 0 ? history[history.length - 1] : 'initial'),
[history],
);

const handleClose = useCallback(() => {
setStep('initial');
setHistory([]);
onClose();
}, [setStep, setHistory, onClose]);
}, [setHistory, onClose]);

const handleBack = useCallback(() => {
const prev = history.pop();
setStep(prev || 'initial');
setHistory(history => (history.length > 0 ? history.slice(0, -1) : []));
}, [history, setStep, setHistory]);
}, [history, setHistory]);

const handleStep = useCallback(
(newStep: Step) => {
setStep(newStep);
setHistory(history => [...history, step]);
setHistory(history => [...history, newStep]);
},
[step, setStep, setHistory],
[setHistory],
);

const props: Props = {
Expand Down

0 comments on commit 9ed2bf9

Please sign in to comment.