5

Coming from a react background, i was wondering where is the state and setState equivalent in lit-element, i couldn't find anything useful in lit-element docs. is it private property? or requestUpdate?

Edderd
  • 85
  • 6
  • Do you mean the `properties`? I think those act as the "state"; every time you set a property, the element is updated/rerendered. https://lit-element.polymer-project.org/guide/lifecycle#haschanged – dork May 23 '19 at 09:13

1 Answers1

5

There is no state in LitElement, at least not directly.

What you have is a set of properties that you define in the static get properties() getter.

They act more or less like state does in rect, everytime one of those properties change, the element is updated.

LostInBrittany
  • 1,172
  • 9
  • 19
  • Are there any best practices available for lit-element if you would like to create immutable properties? – Albert Skibinski Apr 15 '20 at 15:30
  • And `properties` are visible from the outside, and modifiable. So they're not private. It seems they are closer to React `props`. Is there a concept of "private state" in LitElement? – Matthias Dec 29 '20 at 01:59
  • You do have a `@internalProperty()` decorator that you can use for internal properties that should only be changed from within the component https://lit-element.polymer-project.org/api/modules/_lit_element_.html#internalproperty – gitaarik Feb 15 '21 at 11:03