Optimize academy
This commit is contained in:
32
resources/js/bootstrap-lite.js
vendored
Normal file
32
resources/js/bootstrap-lite.js
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
import axios from 'axios'
|
||||
import React from 'react'
|
||||
import { createRoot, hydrateRoot } from 'react-dom/client'
|
||||
|
||||
const csrfToken = typeof document !== 'undefined'
|
||||
? document.querySelector('meta[name="csrf-token"]')?.getAttribute('content')
|
||||
: null
|
||||
|
||||
axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'
|
||||
|
||||
if (csrfToken) {
|
||||
axios.defaults.headers.common['X-CSRF-TOKEN'] = csrfToken
|
||||
}
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
window.axios = axios
|
||||
}
|
||||
|
||||
export function mountInertiaRoot(el, App, props) {
|
||||
if (!el) {
|
||||
return null
|
||||
}
|
||||
|
||||
const node = React.createElement(App, props)
|
||||
const hasServerMarkup = el.childNodes.length > 0 && el.innerHTML.trim() !== ''
|
||||
|
||||
if (hasServerMarkup) {
|
||||
return hydrateRoot(el, node)
|
||||
}
|
||||
|
||||
return createRoot(el).render(node)
|
||||
}
|
||||
Reference in New Issue
Block a user