如何访问react-app中设置的localStorage

时间:2019-05-28 09:13:46

标签: reactjs local-storage

我有这个具有打开我的应用程序功能的javascript,我想访问我在应用程序中设置的localStorage。

function loadMaps(callBack,client) {

    var mapWindow = window.open('http://localhost:3000/?client=' + client, '_blank');
    var timer = setInterval(timer, 500);

    function timer() {
        if (mapWindow.closed) {
            var inputValue = localStorage.getItem('address')
            callBack(inputValue)
            clearInterval(timer);
        }
    }
}

设置localStorage值的反应函数

  handleConfirm = (props, marker) => {
    this.setState({ finalConfirmation: true, confirmation: true }, () => {
      localStorage.setItem('address', JSON.stringify(marker));
      window.close();
    });
  }

我希望该值是一个对象,但我得到的实际值为null。

0 个答案:

没有答案
相关问题