Skip to main content

useSharePointDocumentManager

@spartanfx/react v1.2.2


@spartanfx/react / spfx / useSharePointDocumentManager

Function: useSharePointDocumentManager()

function useSharePointDocumentManager(config): ISharePointDocumentManagerReturn;

Hook for managing SharePoint documents

Configuration

Required

PropertyTypeDescription
libraryNamestringName of the SharePoint library
spSPFIPnPjs SPFI instance (required)

Options

PropertyTypeDescription
autoRefresh?booleanEnable auto-refresh on mutations (default: true)
cacheDuration?numberCache duration in milliseconds (default: 60000 - 1 minute)
rootFolderPath?stringRoot folder path (optional) If not provided, the hook will automatically fetch the library's server-relative URL from SharePoint (e.g., '/sites/mysite/Shared Documents').

Events & callbacks

PropertyTypeDescription
onAfterUpload?(file, item) => void | Promise<void>Callback after successful upload
onBeforeUpload?(file) => Promise<boolean | void>Callback before upload
onError?(error) => voidCallback on error

Full type reference: ISharePointDocumentManagerConfig

Returns

ISharePointDocumentManagerReturn

Example

const {
items,
loading,
uploadFiles,
deleteItems,
refresh
} = useSharePointDocumentManager({
sp: spInstance,
libraryName: 'Documents',
rootFolderPath: '/sites/mysite/Shared Documents'
});