Skip to content

Commit 4e2c16b

Browse files
Return the newly created HtmlElement class, as opposed to just "undef… (#91)
* 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'); ``` * feat: Add types --------- Co-authored-by: Ryan Christian <[email protected]>
1 parent e277fd0 commit 4e2c16b

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/index.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,12 @@ type Options =
4343
* shadow: true,
4444
* mode: 'closed'
4545
* });
46+
* const klass = register(PreactComponent, 'my-component');
4647
* ```
4748
*/
4849
export default function register(
4950
Component: AnyComponent,
5051
tagName?: string,
5152
propNames?: string[],
5253
options?: Options
53-
): void;
54+
): HTMLElement;

src/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,12 @@ export default function register(Component, tagName, propNames, options) {
7575
});
7676
});
7777

78-
return customElements.define(
78+
customElements.define(
7979
tagName || Component.tagName || Component.displayName || Component.name,
8080
PreactElement
8181
);
82+
83+
return PreactElement;
8284
}
8385

8486
function ContextProvider(props) {

0 commit comments

Comments
 (0)