Skip to content

Commit c97dce9

Browse files
authored
Return the newly created HtmlElement class, as opposed to just "undefined"
Currently `register` returns the result of `customElements.define`, which happens to be undefined. While it is possible to get the just defined tab right away, it would make sense to return the newly create HtmlElement class instead. ```js const klass = register(Component, 'element-tag'); ``` vs ```js register(Component, 'element-tag'); const klass = customElements.get('element-tag'); ```
1 parent 9980548 commit c97dce9

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import { h, cloneElement, render, hydrate } from 'preact';
3535
* shadow: true,
3636
* mode: 'closed'
3737
* });
38+
* @returns {HtmlElement} a newly created class extending HtmlElement that wraps the Preact component.
3839
* ```
3940
*/
4041
export default function register(Component, tagName, propNames, options) {
@@ -93,10 +94,12 @@ export default function register(Component, tagName, propNames, options) {
9394
});
9495
});
9596

96-
return customElements.define(
97+
customElements.define(
9798
tagName || Component.tagName || Component.displayName || Component.name,
9899
PreactElement
99100
);
101+
102+
return PreactElement;
100103
}
101104

102105
function ContextProvider(props) {

0 commit comments

Comments
 (0)