Common hooks

The optional src/common-hooks.js (or .ts, .jsx, .tsx) file can be used to implement customizations that are common to the server and the client:

import type { CommonHooks } from "rakkasjs";

const hooks: CommonHooks = {
  extendPageContext(ctx) {
    // Add properties to the page context,
    // especially to ctx.locals.
    // Extensions added here will be
    // available both on the server and the client.
    // Client and server `extendPageContext` hooks
    // will be called _before_ this.
  },
  wrapApp(app) {
    // Wrap the Rakkas application in some provider
    // component.
    return <SomeProvider>{app}</SomeProvider>;
  },
  beforePageLookup(ctx) {
    // This will be called before the page route
    // lookup is performed.
    // - Return `false` to prevent the page from rendering.
    // - Return `{ redirect: "/some/url" }` to redirect.
    // - Return `{ rewrite: "/new/url" }` to render as if the URL was `/new/url`.
    // - Return true to continue as normal.
  },
};

export default hooks;