Local File System
The local filesystem is import fs from 'fs/promises'
Note
The readFile
method is used in the example below, but you can use any of the methods from the built-in module.
Beta Note
The current imeplementation and documentation is in beta and is subject to change.
The current implementation is a patch solution to allow the use of the built-in module in Djot - it is not the final solution.
Usage
tsx
import localFs from '#djot/local-fs'
const readFile = (...args) => localFs('readFile', ...args)
export const App = () => {
const [output, setOutput] = React.useState('')
const handleClick = async () => {
const data = await readFile('README.md')
setOutput(data)
}
return (
<>
<button onClick={handleClick}>Read</button>
<pre>{output}</pre>
</>
)
}
import localFs from '#djot/local-fs'
const readFile = (...args) => localFs('readFile', ...args)
export const App = () => {
const [output, setOutput] = React.useState('')
const handleClick = async () => {
const data = await readFile('README.md')
setOutput(data)
}
return (
<>
<button onClick={handleClick}>Read</button>
<pre>{output}</pre>
</>
)
}