SessionStorage Returning NULL when Application Starts

0

I have a function that is bound to a button, which saves a value in sessionStorage.setItem , and redirects to another page.

Arquivo cliente.js

    pegaValorConta(id) {
     sessionStorage.setItem('id-cliente-conta', id);
     window.location.href = 'http://192.168.0.109:3000/conta';
  }

and I want to display what's inside sessionStorage on page conta.js

Arquivo conta.js

      componentWillMount() {

         console.log("Session: ",sessionStorage.getItem('id-cliente-conta'));
    }

The problem is that the first time I start the application and I execute the function above, the sessionStorage returns null , it only takes the value when I go back to the cliente.js file and redo the function.

How do I sessionStorage not return the value null the first time?

    
asked by anonymous 16.09.2018 / 00:09

0 answers