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
keystring 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</buttonReturns function linkStateSetter(e)
Accepts props and state, and returns a new Virtual DOM tree to build.
Virtual DOM is generally constructed via JSX.
Parameters
propsobject Props (eg: JSX attributes) received from parent element/componentstateobject The component's current state
Returns **** VNode
Update component state by copying properties from state to this.state.
Parameters
stateobject 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
propsobjectstateobject
Parameters
nodeNameattributesargs...
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
vnodeVNode 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
vnodeVNode A (JSX) VNode to renderparentElement 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
propsObjectopts[Object]opts.renderSync[boolean] Iftrueandoptions.syncComponentUpdatesistrue, triggers synchronous rendering. (optional, defaultfalse)opts.render[boolean] Iffalse, no render will be triggered. (optional, defaulttrue)
component
Virtual DOM Node
Parameters
nodeNameattributeschildren