piral-core
Version:
The core library for creating a Piral instance.
23 lines • 908 B
JavaScript
import * as React from 'react';
import { useGlobalState } from '../hooks';
import { defaultRender, none } from '../utils';
function renderComponent(components, props) {
const name = props.type;
const Component = components[name];
if (process.env.NODE_ENV === 'development') {
React.useEffect(() => console.error('[dev-info] An error occurred in the Piral instance.', props), none);
}
if (!Component) {
const Unknown = components.unknown;
if (Unknown) {
return React.createElement(Unknown, { ...props, type: "unknown" });
}
return defaultRender(`Error: ${props.type}`);
}
return React.createElement(Component, { ...props });
}
export const SwitchErrorInfo = (props) => {
const components = useGlobalState((m) => m.errorComponents);
return renderComponent(components, props);
};
//# sourceMappingURL=SwitchErrorInfo.js.map