Hiyve Components - v1.0.0
    Preparing search index...

    Function useNotePersistence

    • Hook for note persistence with auto-save.

      Parameters

      Returns UseNotePersistenceResult

      Persistence state and controls

      This hook provides automatic saving of notes to file storage. It uses the Hiyve client's file upload/modify APIs to persist data to S3.

      Features:

      • Auto-save after a configurable interval (default: 3 seconds)
      • Debounced saving to prevent excessive API calls
      • Saves on unmount to prevent data loss
      • Handles first save vs subsequent saves automatically
      • Tracks save status (saving, saved, unsaved changes)
      function NoteWithPersistence() {
      const { client } = useClient();
      const { localParticipant } = useParticipants();
      const [content, setContent] = useState<JSONContent>(EMPTY_CONTENT);
      const [title, setTitle] = useState('');

      const {
      fileId,
      isSaving,
      hasUnsavedChanges,
      lastSaved,
      save,
      markUnsaved,
      } = useNotePersistence({
      client,
      content,
      title,
      enabled: true,
      userId: localParticipant?.userId ?? '',
      userName: localParticipant?.name,
      onSaved: (id) => console.log('Saved to:', id),
      });

      // Mark unsaved when content changes
      useEffect(() => {
      markUnsaved();
      }, [content, markUnsaved]);

      return <NoteEditor onChange={setContent} />;
      }