# code/editor/useFileDocument (zidane-ui/code/editor)

Import: `import { … } from 'zidane-ui/code/editor'`. Source: [ui/src/code/editor/useFileDocument.ts](https://github.com/Tahul/zidane/blob/main/ui/src/code/editor/useFileDocument.ts).

## Functions

### `useFileDocument`

Function.

Loads one adapter file for `useCodeDocument` and keeps it fresh as the adapter reports changes.

```ts
function useFileDocument(fs: FileSystemAdapter, path: string): FileDocumentState
```

**Parameters**

- `fs` (`FileSystemAdapter`): Where the file lives.
- `path` (`string`): The file, from the adapter's root.

**Returns** `FileDocumentState`

Source: [ui/src/code/editor/useFileDocument.ts:31](https://github.com/Tahul/zidane/blob/main/ui/src/code/editor/useFileDocument.ts#L31)

## Interfaces

### `FileDocumentState`

Interface.

What [`useFileDocument`](https://zidane.si/docs/reference/ui-code-editor-use-file-document.md#useFileDocument) returns: the file as a `CodeDoc` plus the save and reload `useCodeDocument` takes.

```ts
interface FileDocumentState
```

**Properties**

- `doc` (`CodeDoc | null`): The latest read; `null` until the first one lands.
- `error` (`string | null`): Why the file could not be read.
- `reload` (`() => Promise<CodeDoc | null>`): Reads the file again; `null` when it cannot be read.
- `save` (`(text: string, base: CodeDoc, force: boolean) => Promise<SaveOutcome<CodeDoc>>`): Writes `text`; unless `force`, first checks the file still has `base`'s version and reports `changed` if not.

Source: [ui/src/code/editor/useFileDocument.ts:12](https://github.com/Tahul/zidane/blob/main/ui/src/code/editor/useFileDocument.ts#L12)
