fix: use ref instead of state for initialization flag to prevent dependency array size change

This commit is contained in:
Unchained
2026-03-28 18:41:36 +02:00
parent 676dda4642
commit b78b081d29

View File

@@ -30,16 +30,16 @@ export default function CartDrawer() {
const lines = getLines(); const lines = getLines();
const total = getTotal(); const total = getTotal();
const lineCount = getLineCount(); const lineCount = getLineCount();
const [initialized, setInitialized] = useState(false); const initializedRef = useRef(false);
useEffect(() => { useEffect(() => {
if (!initialized && locale) { if (!initializedRef.current && locale) {
// Set language code before initializing checkout // Set language code before initializing checkout
useSaleorCheckoutStore.getState().setLanguageCode(locale); useSaleorCheckoutStore.getState().setLanguageCode(locale);
initCheckout(); initCheckout();
setInitialized(true); initializedRef.current = true;
} }
}, [initialized, locale]); }, [locale]);
useEffect(() => { useEffect(() => {
if (isOpen) { if (isOpen) {