## React from a local ESM bundle
### Basic setup
```html
Zero-Build React App
```
### React with htm (no JSX, no build)
```javascript
// index.js
import { React, createRoot, htm } from '@app/runtime';
const { useState, useEffect, useRef } = React;
// Bind htm to React.createElement
const html = htm.bind(React.createElement);
// Components use html`` instead of JSX
function App() {
const [records, setRecords] = useState([]);
const [loading, setLoading] = useState(true);
const [search, setSearch] = useState('');
useEffect(() => {
loadData();
}, []);
async function loadData() {
try {
const response = await fetch('data/archive-data.json');
const data = await response.json();
setRecords(data.records);
} catch (error) {
console.error('Failed to load data:', error);
} finally {
setLoading(false);
}
}
const filtered = records.filter(r =>
r.title.toLowerCase().includes(search.toLowerCase())
);
if (loading) {
return html``;
}
return html`
<${RecordList} records=${filtered} />
`;
}
function RecordList({ records }) {
return html`
${records.map(record => html`
<${RecordCard} key=${record.id} record=${record} />
`)}
`;
}
function RecordCard({ record }) {
return html`
${record.title}
${record.publication_date}
${record.summary}
${record.tags?.map(tag => html`
${tag}
`)}
`;
}
// Mount app
const root = createRoot(document.getElementById('root'));
root.render(html`<${App} />`);
```
## Data caching with localStorage
```javascript
// services/cacheService.js
const CACHE_TTL = 60 * 60 * 1000; // 1 hour
export function getCached(key) {
const cached = localStorage.getItem(key);
if (!cached) return null;
try {
const { data, timestamp } = JSON.parse(cached);
if (Date.now() - timestamp > CACHE_TTL) {
localStorage.removeItem(key);
return null;
}
return data;
} catch {
localStorage.removeItem(key);
return null;
}
}
export function setCache(key, data) {
localStorage.setItem(key, JSON.stringify({
data,
timestamp: Date.now()
}));
}
export async function fetchWithCache(url, cacheKey) {
// Check cache first
const cached = getCached(cacheKey);
if (cached) return cached;
// Fetch fresh data
const response = await fetch(url);
const data = await response.json();
// Cache for next time
setCache(cacheKey, data);
return data;
}
// Usage
const records = await fetchWithCache('data/archive-data.json', 'archive-records');
```