Current section

Files

Jump to
combo_new templates inertia-react assets src js app.jsx
Raw

templates/inertia-react/assets/src/js/app.jsx

import "vite/modulepreload-polyfill"
import "@fontsource-variable/instrument-sans"
import "../css/app.css"
import axios from "axios"
import { createInertiaApp } from "@inertiajs/react"
import { createRoot, hydrateRoot } from "react-dom/client"
axios.defaults.xsrfCookieName = "CSRF-TOKEN"
axios.defaults.xsrfHeaderName = "X-CSRF-TOKEN"
const appName = "MyApp"
function ssr_mode() {
return document.documentElement.hasAttribute("data-ssr")
}
createInertiaApp({
title: (title) => (title ? `${title} - ${appName}` : appName),
resolve: (name) => {
const page = `./pages/${name}.jsx`
const pages = import.meta.glob("./pages/**/*.jsx", { eager: true })
return pages[page]
},
setup({ el, App, props }) {
if (ssr_mode()) {
hydrateRoot(el, <App {...props} />)
} else {
createRoot(el).render(<App {...props} />)
}
},
})