Skip to content

Commit

Permalink
backport #3863
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed Jan 12, 2024
1 parent 9f33f04 commit ca1a951
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
20 changes: 12 additions & 8 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,14 +270,18 @@ export namespace h {
// Preact render
// -----------------------------------

export function render(
vnode: ComponentChild,
parent: Element | Document | ShadowRoot | DocumentFragment
): void;
export function hydrate(
vnode: ComponentChild,
parent: Element | Document | ShadowRoot | DocumentFragment
): void;
interface ContainerNode {
nodeType: Node['nodeType'];
parentNode: Node['parentNode'];
firstChild: Node['firstChild'];
insertBefore: Node['insertBefore'];
appendChild: Node['appendChild'];
removeChild: Node['removeChild'];
childNodes: ArrayLike<Node>;
}

export function render(vnode: ComponentChild, parent: ContainerNode): void;
export function hydrate(vnode: ComponentChild, parent: ContainerNode): void;
export function cloneElement(
vnode: VNode<any>,
props?: any,
Expand Down
8 changes: 7 additions & 1 deletion test/ts/preact.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ const UseOfComponentWithChildren = () => {
);
};

// Mounting into different types of Nodes
render(h('div', {}), document.createElement('div'));
render(h('div', {}), document);
render(h('div', {}), document.createElement('div').shadowRoot!);
render(h('div', {}), document.createDocumentFragment());

// using ref and or jsx
class ComponentUsingRef extends Component<any, any> {
private array: string[];
Expand All @@ -117,7 +123,7 @@ class ComponentUsingRef extends Component<any, any> {
this.refs = [];
return (
<div jsx>
{this.array.map(el => (
{this.array.map((el) => (
<span ref={this.setRef}>{el}</span>
))}

Expand Down

0 comments on commit ca1a951

Please sign in to comment.