routelit-client
v0.5.5
Published
Routelit React Client for building data and web applications in python over http.
Readme
Routelit React client

This is the react client for the Routelit. It is not supposed to be used alone, but rather as part of the python Routelit library. And just if you want to build custom components.
Routelit is an agnostic library for building data and web applications in python over http.
This library contains core and basic components.
Core components
- container
- dialog
- form
- fragment
- image
- link
- markdown
- headings
- checkbox (with label)
- single-checkbox
- checkbox_group
- radio (group)
- select
- textarea (with label)
- single-textarea
- text_input (with label)
- single-text-input
- button
- expander
- heading
- title
- header
- subheader
Public API (exports from src/lib.ts)
- This section documents everything you can import from
src/lib.ts(and what is exposed onwindow).
Globals
React: Re-exported and also attached towindow.Reactfor non-bundled environments.ReactDOM: Re-exported and also attached towindow.ReactDOM.jsxRuntime: Re-exported and attached towindow.jsxRuntimewithjsx,jsxs, andFragmentfor JSX runtime needs.RoutelitClient: Singleton attached towindow.RoutelitClientthat aggregates the most common API surface.- Example:
const { manager, componentStore, renderApp } = window.RoutelitClient!; renderApp("root");
- Example:
Singletons
manager(RouteLitManager): Central event/state manager. Handlesroutelit:eventdispatch, navigation, throttled action batching, and subscriptions to loading and error state.componentStore(ComponentStore): Registry used by the renderer and components. Pre-registered with the core components listed above; you can extend it withcomponentStore.register(name, Component)and then use thatnamefrom the server.
Rendering
renderApp(rootId?: string): Mounts the app (default element id isroot).
Hooks (context-aware)
useDispatcherWith(id, type): Returns a(data: Record<string, unknown>) => voidthat dispatches a custom Routelit event{ id, type, ...data }.useDispatcherWithAttr(id, type, attr): Returns a(value: unknown) => voidthat dispatches{ id, type, [attr]: value }.useFormDispatcher(id, type): LikeuseDispatcherWith, but includes the currentformIdin the payload. Useful inside form controls.useFormDispatcherWithAttr(id, type, attr): LikeuseDispatcherWithAttr, but includesformId.useIsLoading(): Returns a boolean reflecting combined loading state (fragment or app-level).useError(): Returns the lastError(if any) bubbled from the manager chain.
Hooks (UI utilities)
useLinkClickHandler({ id, href, replace, isExternal }): Returns an anchoronClickhandler that dispatches anavigateevent. Prevents default for internal links; lets external links proceed.useRLInlineElement(props, elementKeys): Converts inline element descriptors onpropsto rendered elements using theComponentStore(e.g., slots likeleftIcon,rightIcon).useRLCallbackAttributes(props, rlCallbackAttrs): Converts string function bodies found onpropsat the listed attribute names into real callbacks and returns them. Note: only use with trusted input.
Higher-order components (HOCs)
withSimpleComponent(Component, props?): Wraps any element/component, merging optionalpropsand mapping anyrlInlineElementsAttrsinto real inline elements.- Example:
const Title = withSimpleComponent("h1", { className: "title" });
- Example:
withEventDispatcher(Component, options?): Attaches an event handler that dispatches a Routelit event (defaults:rlEventName="click",rlEventAttr="onClick"). Works well for buttons.- Example:
const Button = withEventDispatcher("button", { type: "button" }); // <Button id="save">Save</Button>
- Example:
withValueEventDispatcher(Component, options?): Attaches a value-change handler that dispatches{ [rlValueAttr]: value }(defaults:change/onChange/value).- Examples:
const TextInput = withValueEventDispatcher("input", { type: "text" }); const Checkbox = withValueEventDispatcher("input", { type: "checkbox", rlValueAttr: "checked", rlEventValueGetter: (e) => e.currentTarget.checked, });
- Examples:
withInputValueEventDispatcher(Component, options?): For text inputs/textareas; dispatches achangewithvalueononBluror when pressing Enter. Defaults wire uponBlur/onKeyDownand read fromdefaultValue.- Example:
const TextArea = withInputValueEventDispatcher("textarea");
- Example:
withCallbackAttributes(Component, { rlCallbackAttrs? }): Converts string callbacks on the listed attribute names into real functions and forwards them to the wrapped component.
