A function that registers a file dependency for hot reload during development. When the file changes, the loader will automatically re-run and refresh data on the client without a full page reload.
app/blog/[slug].tsx
import { watchFile } from 'one'
import { readFile } from 'fs/promises'
export async function loader({ params: { slug } }) {
const filePath = `./content/${slug}.mdx`
watchFile(filePath)
const content = await readFile(filePath, 'utf-8')
return { content }
}
fs.readFile or similarEdit this page on GitHub.