-
Notifications
You must be signed in to change notification settings - Fork 1
API
These are the methods exported by Preact 8.
import { h, createElement,
cloneElement, createRef, Component,
render, rerender, options,
} from 'preact'
- On This Page
h(nodeName, attributes=, ...args): !VNode
cloneElement(vnode, props=, ...args): !VNode
createRef(): !Object
render(vnode, parent, merge=): void
rerender(): void
There are special properties that can be passed to the Preact component. They are defined in the PreactProps type to prevent renaming by the compiler, but this type extends Object.
Name | Type & Description |
---|---|
dangerouslySetInnerHTML | { __html: * } |
Sets HTML of the node without escaping the contents. | |
ref | function(?) |
The reference callback for the node. |
Accepted children are _VNode_s and primitives, and arrays of them.
(VNode | string | boolean | number | undefined)
AcceptedChild
: A child node that can be passed to some methods.
h(
nodeName: string|!Function,
attributes=: PreactProps,
...args: AcceptedChild|Array<AcceptedChild>,
): !VNode
The pragma (rendering) function.
-
nodeName*
(string | !Function)
: An element name. Ex:div
,a
,span
, etc. -
attributes
PreactProps
(optional): Any attributes/props to set on the created element. -
...args
(AcceptedChild | Array<AcceptedChild>)
(optional): Additional arguments are taken to be children to append. Can be infinitely nested Arrays.
Alias: createElement
.
cloneElement(
vnode: !VNode,
props=: PreactProps,
...args: AcceptedChild|Array<AcceptedChild>,
): !VNode
Clones the given VNode, optionally adding attributes/props and replacing its children.
-
vnode*
!VNode
: The virtual DOM element to clone. -
props
PreactProps
(optional): Attributes/props to add when cloning. -
...args
(AcceptedChild | Array<AcceptedChild>)
(optional): Any additional arguments will be used as replacement children.
Just returns an object...?
Render JSX into a parent
Element.
-
vnode*
!VNode
: A (JSX) VNode to render. -
parent*
Element
: DOM element to render into. -
merge
Element
(optional): Attempt to re-use an existing DOM tree rooted atmerge
.
Rerenders all rendered elements.
Most of documentation comes from Preact authors, for example https://preactjs.com/guide/api-reference.
The externs were created to be used with JavaScript Compiler: https://compiler.page.
![]() |
© Art Deco™ for Depack 2020 |
---|