feat: auth & admin
This commit is contained in:
@@ -21,45 +21,49 @@ React DOM provides APIs to hint the browser about resources it will need. These
|
||||
**Example (preconnect to third-party APIs):**
|
||||
|
||||
```tsx
|
||||
import { preconnect, prefetchDNS } from 'react-dom'
|
||||
import { preconnect, prefetchDNS } from 'react-dom';
|
||||
|
||||
export default function App() {
|
||||
prefetchDNS('https://analytics.example.com')
|
||||
preconnect('https://api.example.com')
|
||||
prefetchDNS('https://analytics.example.com');
|
||||
preconnect('https://api.example.com');
|
||||
|
||||
return <main>{/* content */}</main>
|
||||
return <main>{/* content */}</main>;
|
||||
}
|
||||
```
|
||||
|
||||
**Example (preload critical fonts and styles):**
|
||||
|
||||
```tsx
|
||||
import { preload, preinit } from 'react-dom'
|
||||
import { preload, preinit } from 'react-dom';
|
||||
|
||||
export default function RootLayout({ children }) {
|
||||
// Preload font file
|
||||
preload('/fonts/inter.woff2', { as: 'font', type: 'font/woff2', crossOrigin: 'anonymous' })
|
||||
preload('/fonts/inter.woff2', {
|
||||
as: 'font',
|
||||
type: 'font/woff2',
|
||||
crossOrigin: 'anonymous',
|
||||
});
|
||||
|
||||
// Fetch and apply critical stylesheet immediately
|
||||
preinit('/styles/critical.css', { as: 'style' })
|
||||
preinit('/styles/critical.css', { as: 'style' });
|
||||
|
||||
return (
|
||||
<html>
|
||||
<body>{children}</body>
|
||||
</html>
|
||||
)
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
**Example (preload modules for code-split routes):**
|
||||
|
||||
```tsx
|
||||
import { preloadModule, preinitModule } from 'react-dom'
|
||||
import { preloadModule, preinitModule } from 'react-dom';
|
||||
|
||||
function Navigation() {
|
||||
const preloadDashboard = () => {
|
||||
preloadModule('/dashboard.js', { as: 'script' })
|
||||
}
|
||||
preloadModule('/dashboard.js', { as: 'script' });
|
||||
};
|
||||
|
||||
return (
|
||||
<nav>
|
||||
@@ -67,19 +71,19 @@ function Navigation() {
|
||||
Dashboard
|
||||
</a>
|
||||
</nav>
|
||||
)
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
**When to use each:**
|
||||
|
||||
| API | Use case |
|
||||
|-----|----------|
|
||||
| `prefetchDNS` | Third-party domains you'll connect to later |
|
||||
| `preconnect` | APIs or CDNs you'll fetch from immediately |
|
||||
| `preload` | Critical resources needed for current page |
|
||||
| `preloadModule` | JS modules for likely next navigation |
|
||||
| `preinit` | Stylesheets/scripts that must execute early |
|
||||
| `preinitModule` | ES modules that must execute early |
|
||||
| API | Use case |
|
||||
| --------------- | ------------------------------------------- |
|
||||
| `prefetchDNS` | Third-party domains you'll connect to later |
|
||||
| `preconnect` | APIs or CDNs you'll fetch from immediately |
|
||||
| `preload` | Critical resources needed for current page |
|
||||
| `preloadModule` | JS modules for likely next navigation |
|
||||
| `preinit` | Stylesheets/scripts that must execute early |
|
||||
| `preinitModule` | ES modules that must execute early |
|
||||
|
||||
Reference: [React DOM Resource Preloading APIs](https://react.dev/reference/react-dom#resource-preloading-apis)
|
||||
|
||||
Reference in New Issue
Block a user