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

203
Visualizações
lit: simple button click changing reactive property doesn't cause a re-render

I have super simple lit element and I'm trying to have a closed or open icon based on isOpen reactive property. Clicking on the element sets this.isOpen = !this.isOpen, which should cause an update. Unfortunately, clicking on the button doesn't cause a re-render. Any ideas why this is happening? Console.log logs out true false true false tue correctly when spamming clicks.

edit: changed isOpen to a string open and closed. No effect.
edit2: changed isOpen to @state(). No effect.
edit3: added this.requestUpdate() and it works. But it makes no sense! What is so "reactive" about "reactive" properties if changing them doesn't cause a re-render or even trigger lifecycle methods??????

@customElement('header-top')
export class HeaderTop extends LitElement {
  static styles = css`
    :host {
      display: block;
    }
    :host([hidden]) {
      display: none;
    }
    .settings-btn {
      display: inline-block;
      width: 2rem;
      height: 2rem;
      fill: white;
      cursor: pointer;
      padding: 0;
      margin: 0;
      border: none;
      background: none;
    }
    .settings-btn:hover {
    }
  `;

  @property({ type: Boolean })
  isOpen = false;

  public render() {
    console.log(no-rerender).
    return html`<header>
      <nav>
        ${this.isOpen
          ? html`<button
              class="settings-btn close"
              @click="${this._openOrCloseMenu}"
            >
              <i>${close}</i>
            </button>`
          : html`<button
              class="settings-btn open"
              @click="${this._openOrCloseMenu}"
            >
              <i>${equalizer}</i>
            </button>`}
      </nav>
    </header>`;
  }

  public _openOrCloseMenu(e: Event) {
    console.log(this.isOpen); // triggers
    this.isOpen = !this.isOpen;
  }
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Apparantly reactive properties are only reactive if it is part of the DOM Element API. You can turn this off by setting ({attribute: false}) and it will re-render.

about 4 years ago · Juan Pablo Isaza Relatório
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