Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

199
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda