Packages

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

Retired package: Release invalid - Not production-ready, LiveView 1.0.x compatibility issue

Current section

Files

Jump to
react_phx assets dist errorBoundary.js
Raw

assets/dist/errorBoundary.js

import { Component, createElement } from "react";
export class ReactPhxErrorBoundary extends Component {
constructor() {
super(...arguments);
this.state = { hasError: false, error: null };
}
static getDerivedStateFromError(error) {
return { hasError: true, error };
}
componentDidCatch(error, errorInfo) {
console.error(`react_phx: Error in component "${this.props.componentName}":`, error, errorInfo);
}
componentDidUpdate(prevProps) {
if (prevProps.children !== this.props.children) {
this.setState({ hasError: false, error: null });
}
}
render() {
if (this.state.hasError) {
const { error } = this.state;
const { componentName } = this.props;
return createElement("div", {
style: {
padding: "16px",
margin: "8px",
background: "#fef2f2",
border: "1px solid #fca5a5",
borderRadius: "8px",
color: "#991b1b",
fontSize: "13px",
fontFamily: "monospace",
},
}, createElement("strong", null, `react_phx error in <${componentName || "Unknown"}>:`), createElement("pre", { style: { marginTop: "8px", whiteSpace: "pre-wrap", fontSize: "12px" } }, error?.message || "Unknown error"));
}
return this.props.children;
}
}