Packages

React inside Phoenix LiveView — async code splitting, client-side props diffing, and zero-config component discovery.

Retired package: Release invalid - Not production-ready

Current section

Files

Jump to
react_phx assets useLiveEvent.ts
Raw

assets/useLiveEvent.ts

import { useEffect, useRef } from "react";
import { useLiveReact } from "./context";
export function useLiveEvent(event: string, callback: (payload: any) => void): void {
const { handleEvent, removeHandleEvent } = useLiveReact();
const callbackRef = useRef(callback);
callbackRef.current = callback;
useEffect(() => {
const ref = handleEvent(event, (payload: any) => callbackRef.current(payload));
return () => removeHandleEvent(ref);
}, [event]);
}