Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LitHauntedElement: No re-render observed when incoming prop changed #341

Open
barryf001 opened this issue Dec 22, 2021 · 3 comments
Open

Comments

@barryf001
Copy link

barryf001 commented Dec 22, 2021

Hi,

Relates to LitElementHaunted usage.

Could you explain why when a state variable is passed to a child component (as per example code) there is no re-rendering of the child component? Maybe I'm using this incorrectly but this seems the most intutive usage..

import { html } from 'lit-element';
import { litHaunted } from './lit-haunted-element.js';
import { useState } from 'haunted'


const CounterChild = litHaunted(({count}) => {

  return html`
    <h1>${count}</h1>
  `;
});

window.customElements.define('my-counter-child', CounterChild);


const Counter = litHaunted(() => {

  const [count, setCount] = useState(0);

  return html`
      <p>A paragraph</p>
      <button type="button" @click=${() => { setCount(count + 1)}}>Increment</button>
      <p><strong>Count:</strong> ${count}</p>
    <div>
    <my-counter-child .count=${count}></my-counter-child>
   </div>
  `;
});

window.customElements.define('my-counter', Counter);
@matthewp
Copy link
Owner

What is LitHauntedElement and how does it differ from component?

@barryf001
Copy link
Author

From the examples for integration with LitElement
https://github.com/matthewp/haunted/blob/main/examples/lit/lit-haunted-element.js

@bennypowers
Copy link
Collaborator

what do you mean by "state variable is passed to a child component"?

do you mean $("my-counter").count = 3? in that case, count hasn't been defined on the class as an observed property, so LitElement's lifecycle won't pick up changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants