'call an API after setting item in localstorage

I want to call an API only after setting a user token in localstorage.

  const loginSuccess = async (data)=>{
   setItemInLocalStorage("ACCESS_TOKEN", data?.access_token); // setting item in localstorage
   dispatch(actions.getUserDetail({ userId: loggedUser.Sid })); // calling API
  }

setItemInLocalStorage function :

function setItemInLocalStorage(key, value) {
    let localValue;
    if (typeof value === 'object') {
        localValue = JSON.stringify(value);
        localStorage.setItem(key, localValue);
    } else {
        localStorage.setItem(key, value);
    }
    if(key === "ACCESS_TOKEN") {
        ACCESS_TOKEN = value;
    }
}

How can I do this ?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source