Lit-html: [Question] How can I re-render the content whether a event is fired?

Created on 23 Mar 2018  路  6Comments  路  Source: Polymer/lit-html

Medium

Most helpful comment

The answer to this question has changed, for LitElement this now appears to be this.requestUpdate()

All 6 comments

I'm assuming you mean "when an" event is fired right?
Just call render again with the same template in your event handler.

@fafcrumb,

I have modular components, so I can't reference it externally. How can I do it internally, like React's setState?

For example,

// incrementor
export default = () => {
    let i = 0;

    const handleClick = () => {
        i++;
        // re-render me, please!
    };

    return html`
        <div>
            <span>${i}</span>
            <button on-click="${handleClick}">CLICK ME</button>
        </div>
    `;
}

That example isn't a component, just a template. Are you using something for a component model?

In LitElement for example you'd call this.invalidate().

Got it! Thanks, @justinfagnani @fafcrumb! I'm studying lit-html to create a simpler component model using Gesco.

The answer to this question has changed, for LitElement this now appears to be this.requestUpdate()

Thanks for the edit @KeithHenry ;)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

depeele picture depeele  路  3Comments

gkjohnson picture gkjohnson  路  5Comments

MVSICA-FICTA picture MVSICA-FICTA  路  5Comments

fopsdev picture fopsdev  路  5Comments

justinfagnani picture justinfagnani  路  4Comments