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 total = getTotal();
const lineCount = getLineCount();
const [initialized, setInitialized] = useState(false);
const initializedRef = useRef(false);
useEffect(() => {
if (!initialized && locale) {
if (!initializedRef.current && locale) {
// Set language code before initializing checkout
useSaleorCheckoutStore.getState().setLanguageCode(locale);
initCheckout();
setInitialized(true);
initializedRef.current = true;
}
}, [initialized, locale]);
}, [locale]);
useEffect(() => {
if (isOpen) {