lit-elementlit-htmllit

React-like refs in lit-html / lit-element?


Does lit-html have by any change something like React's ref feature? For example in the following pseudo-code inputRef would be a callback function or an object { current: ... } where lit-html could pass/set the HTMLElement instance of the input element when the input element is created/attached.

// that #ref pseudo-attribute is fictional
html`<div><input #ref={inputRef}/></div>`

Thanks.


Solution

  • As @WeiChing has mentioned somewhere above, since Lit version 2.0 you can use the newly added directive ref for that: https://lit.dev/docs/templates/directives/#ref