fix: use ref instead of state for initialization flag to prevent dependency array size change
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user