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 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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user