Usage

import { useWatchTextFile } from '@replit/extensions-react';

const Component = () => {
  const { content, watching, watchError, writeChange } = useWatchTextFile({ filePath: "..." });

  ...
}

Signature

function useWatchTextFile({
  filePath: string | null | undefined
}): UseWatchTextFileLoading | UseWatchTextFileErrorLike | UseWatchTextFileWatching;

Result

PropertyTypeDescription
statusUseWatchTextFileStatusThe file watcher’s status. Useful for ensuring the desired file is being watched.
contentstring | nullIf watching, the contents of the file located at the provided filePath
watchErrorstring | nullIf an error occurs, the corresponding error message
writeChangeWriteChange | nullIf watching, a function to update the watched file

Types

TextChange

PropertyType
fromnumber
to?number
insert?string

UseWatchTextFileErrorLike

PropertyType
statusUseWatchTextFileStatus.Error | UseWatchTextFileStatus.Moved | UseWatchTextFileStatus.Deleted
contentnull
watchErrorstring | null
writeChangenull

UseWatchTextFileLoading

PropertyType
statusUseWatchTextFileStatus.Loading
contentnull
watchErrornull
writeChangenull

UseWatchTextFileWatching

PropertyType
statusUseWatchTextFileStatus.Watching
contentstring
watchErrornull
writeChangeWriteChange

UseWatchTextFileStatus

Error = "error",
Loading = "loading",
Watching = "watching",
Moved = "moved",
Deleted = "deleted",

WriteChange

(changes: TextChange | Array<TextChange>) => void