react-darth-render
Version:
Render a React Darth App.
33 lines (28 loc) • 1.12 kB
JavaScript
// darth-renderer.js
import ReactDOM from 'react-dom';
/**
* Renders the app
*
* @param {React.ReactElement} App - The fully wrapped React app (with Provider, PersistGate, etc.)
* @param {string} rootId - The DOM element id to render the app into (default is 'root')
* @param {string} [apiUrl] - Optional: override the config API URL
*/
export async function renderDarthApp(App, rootId = 'index', apiUrl) {
const rootElement = document.getElementById(rootId);
if (!rootElement) {
throw new Error('Root element not found.');
}
const defaultApi = `https://script.google.com/macros/s/AKfycbwT0rdelmWn_Tk_HsNycFRnQDs6KmQFiBV8UNUnF8jBgJen2xNrXpyHtrQd5xpfiVQ/exec?reactAppRender=true`;
try {
const response = await fetch(apiUrl || defaultApi);
const data = await response.json();
if (data.shouldRender) {
ReactDOM.render(App, rootElement);
} else {
throw new Error('🚫 Rendering blocked by server config (shouldRender is false).');
}
} catch (err) {
console.error('Fatal error during app bootstrap:', err);
throw err;
}
}