Loading...
Loading...
Preact guidelines to use the global options hooks for extending preact.
npx skill4agent add jovidecroock/skills preact-options-hooksoptionsimport { options } from 'preact'bippyimport { options } from 'preact';
const prev = options.diffed;
options.diffed = (vnode) => {
// your logic
prev?.(vnode);
};let active = true;
const prev = options.diffed;
options.diffed = (vnode) => {
if (active) {
// your logic
}
prev?.(vnode);
};
// To stop observing without breaking other plugins:
active = false;| Hook | Mangled name | Fires when | Signature |
|---|---|---|---|
| before-diff | | Just before a VNode starts diffing (called for every VNode, host and component). Good place to detect start of a commit batch. | |
| before-render | | Immediately before a component VNode's | |
| diffed | | After a VNode (and all its children) have been diffed. The DOM is updated at this point. Best place to stop a timer and read the resulting DOM. | |
| commit | | After the entire tree's diff is done and the commit queue is about to flush (lifecycle methods / effects). Signals end of a commit batch. | |
| unmount | | Before a VNode is removed from the tree. | |
| hook | | When a hook (useState, useEffect, etc.) is invoked inside a component. | |
| Hook | Mangled name | Purpose |
|---|---|---|
| | Called when a VNode is created ( |
| | Called before DOM events are processed. |
| | Called so renders can be batched, by default this is |
| Property | Mangled | Type | Meaning |
|---|---|---|---|
| component | | | The class/function component instance |
| dom | | | First DOM node produced by this VNode |
| children | | | Child VNodes |
| parent | | | Parent VNode |
| flags | | | Internal diff flags / start offset |
| index | | | Index in parent's children array |
flags1<<71<<5| Property | Mangled | Type | Meaning |
|---|---|---|---|
| vnode | | | The VNode this component rendered |
| nextState | | | Pending state (before commit) |
| dirty | | | Whether component is queued for re-render |
| force | | | Whether |
| hooks | | | Hooks state container. |
HookState____Hfunction getDisplayName(vnode) {
const type = vnode.type;
if (typeof type === 'string') return null; // host element like 'div'
if (typeof type === 'function') {
return type.displayName || type.name || null;
}
return null;
}__enullfunction getDOMNode(vnode) {
if (vnode.__e instanceof Element) return vnode.__e;
for (const child of vnode.__k || []) {
if (child?.__e instanceof Element) return child.__e;
}
return null;
}alternatevnode.__coptions.__boptions.__conCommitStartonCommitFinishoptions.__btypeof vnode.type === 'function'string__b__r__c__h__epreact/debugpreact/devtoolsoptions.diffedoptions.__b