Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

238
Visualizações
JavaScript/Stencil: Generic Modal, with State via sessionStorage: How keep track of id

I try to create in Stencil.js a modal component. It has text and a closing button. After closing, I want to persist the state in the session storage, so that the modal will not be seen in this session anymore.

I kept track of which is which modal, by passing an id-prop, where I implemented the component.

My goal is, that no id needs to be passed via html attribute, but is created in component and stored in the sessionStorage (uuid: 0), which increments, when a new component is instanced. . My problem is, that after a reload, the uuid keeps incrementing, but by the component id and the one in the sessionStorage differ ...

Is there a way, to solve that probelm (hope it make) sense.

Here is a fragement of the component, the function which runs on component init:

  connectedCallback() {
    const readSession = JSON.parse(sessionStorage.getItem('componentsState'));

    const initSession = {
      uuid: 0,
    };

    if (!readSession) {
      sessionStorage.setItem('componentsState', JSON.stringify(initSession));
      this.popupuuid = initSession.uuid;
    } else {
      console.log(readSession);

      // if(this.popupuuid !== readSession.uuid) {
        
      // }

      readSession.uuid++;
      this.popupuuid = readSession.uuid;
      console.log(this.popupuuid);

      sessionStorage.setItem('componentsState', JSON.stringify(readSession));
    }
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda