This is a first crack at generated docs for Preact.
Base Component class, for he ES6 Class method of creating Components
Examples
class MyFoo extends Component {
render(props, state) {
return <div />;
}
}
Returns a function that sets a state property when called. Calling linkState() repeatedly with the same arguments returns a cached link function.
Provides some built-in special cases:
- Checkboxes and radio buttons link their boolean `checked` value
- Inputs automatically link their `value` property
- Event paths fall back to any associated Component if not found on an element
- If linked value is a function, will invoke it and use the result
Parameters
key
string The path to set - can be a dot-notated deep keyeventPath
[string] If set, attempts to find the new state value at a given dot-notated path within the object passed to the linkedState setter.
Examples
Update a "text" state value when an input changes:
<input onChange={ this.linkState('text') } />
Set a deep state value on click
<button onClick={ this.linkState('touch.coords', 'touches.0') }>Tap</button
Returns function linkStateSetter(e)
Accepts props
and state
, and returns a new Virtual DOM tree to build.
Virtual DOM is generally constructed via JSX.
Parameters
props
object Props (eg: JSX attributes) received from parent element/componentstate
object The component's current state
Returns **** VNode
Update component state by copying properties from state
to this.state
.
Parameters
state
object A hash of state properties to update with new values
Returns a boolean
value indicating if the component should re-render when receiving the given props
and state
.
Parameters
props
objectstate
object
Parameters
nodeName
attributes
args
...
Examples
/** @jsx h *\/
import { render, h } from 'preact';
render(<span>foo</span>, document.body);
Global hook methods
Parameters
$0
$0.attributes
Processes all created VNodes.
Parameters
vnode
VNode A newly-created VNode to normalize/process$0
$0.attributes
Global options
If true
, prop
changes trigger synchronous component updates.
Render JSX into a parent
Element.
Parameters
vnode
VNode A (JSX) VNode to renderparent
Element DOM element to render intomerge
[Element] Attempt to re-use an existing DOM tree rooted atmerge
Examples
// render a div into <body>:
render(<div id="hello">hello!</div>, document.body);
// render a "Thing" component into #foo:
const Thing = ({ name }) => <span>{ name }</span>;
render(<Thing name="one" />, document.querySelector('#foo'));
Trigger all queued component renders.
Set a component's props
(generally derived from JSX attributes).
Parameters
props
Objectopts
[Object]opts.renderSync
[boolean] Iftrue
andoptions.syncComponentUpdates
istrue
, triggers synchronous rendering. (optional, defaultfalse
)opts.render
[boolean] Iffalse
, no render will be triggered. (optional, defaulttrue
)
component
Virtual DOM Node
Parameters
nodeName
attributes
children