Hooks
Hooks provide direct access to plugin features.
Most plugin features can’t be used directly because they depend on internal values managed by the runtime. Hooks wrap these features and return ready-to-use functions, so you never have to pass state or other private values yourself.
Even when accessing your own plugin’s APIs, you should still use hooks!
Hooks provide the final decorated version of a feature. Calling them directly bypasses decoration entirely, which almost always leads to unexpected behavior.
Rules of Hooks
Hooks may only be called inside component or command functions.
They must also run during the initial execution of that function. This means you can call hooks anywhere in the function body, but not inside asynchronous callbacks like Promise.then, setTimeout, or event listeners.
If a hook is called after the component or command has already returned, Inkweaver will throw an exception:
Incorrect Example
// example-command.js
export async function example() {
const { someCommand } = useCommands("somePlugin");
await someCommand();
const { anotherCommand } = useCommands("anotherPlugin"); // Not allowed!
anotherCommand();
}
Correct Example
// example-command.js
export async function example() {
const { someCommand } = useCommands("somePlugin");
const { anotherCommand } = useCommands("anotherPlugin");
await someCommand();
anotherCommand();
}