alepha@docs:~/docs/packages/@alepha-react$
cat core.md
2 min read
Last commit:

#@alepha/react - Core

React components and hooks for building Alepha applications.

#Installation

npm install @alepha/react

#Overview

Provides full-stack React development with declarative routing, server-side rendering, and client-side hydration.

The React module enables building modern React applications using the $page primitive on class properties. It delivers seamless server-side rendering, automatic code splitting, and client-side navigation with full type safety and schema validation for route parameters and data.

#API Reference

#Hooks

Hooks provide a way to tap into various lifecycle events and extend functionality. They follow the convention of starting with use and return configured hook instances.

#useAlepha()

Main Alepha hook.

It provides access to the Alepha instance within a React component.

With Alepha, you can access the core functionalities of the framework:

  • alepha.state() for state management
  • alepha.inject() for dependency injection
  • alepha.events.emit() for event handling etc...

#useClient()

Hook to get a virtual client for the specified scope.

It's the React-hook version of $client(), from AlephaServerLinks module.

#useEvents()

Allow subscribing to multiple Alepha events. See {@link Hooks} for available events.

useEvents is fully typed to ensure correct event callback signatures.

tsx
 1useEvents( 2  { 3    "react:transition:begin": (ev) => { 4      console.log("Transition began to:", ev.to); 5    }, 6    "react:transition:error": { 7      priority: "first", 8      callback: (ev) => { 9        console.error("Transition error:", ev.error);10      },11    },12  },13  [],14);

#useInject()

Hook to inject a service instance. It's a wrapper of useAlepha().inject(service) with a memoization.

On This Page
No headings found...
ready
mainTypeScript
UTF-8packages_alepha_react_core.md