从 Localstorage 检索的数据不新鲜

Retrieved data from Localstorage not fresh

我正在使用调度将数据推送到我的本地存储,然后我将历史推送到 /cart 以进一步

但是数据不是刚刚发送的,直到我强制刷新我的页面。

如何使用 history.push 工作流程始终拥有最新的 localStorage 数据?

const submitHandler = (e) => {
    dispatch(
      saveBeneficiaireProfile({
        firstname,
        identifiant,
        adultCount,
        childCount,
        babyCount,
      })
    );
    props.history.push("/cart");
  };

使用 useEffect 挂钩获取新数据。

useEffect(() => {
    
    const profile = localStorage.getBeneficiaireProfile();
    //Also you can save data to state variable and use anywhere
    
  }, []);//this only initialize once 

检索数据到本地存储

getBeneficiaireProfile = ()=>{
    //Get data from local store and return
}