Skip to main content
Version: 2.1.4

useListFormContext

3p-core v2.1.4


3p-core / useListFormContext

Function: useListFormContext()

useListFormContext(config?): IListFormContext

Custom React hook to initialize or consume a List Form context within an SPFx environment.

When called with a configuration object, it creates a new context instance and manages:

  • SharePoint list metadata
  • List item loading (new or existing)
  • Field schema and state mapping
  • Validation state and error messages
  • Attachment management
  • Data binding via formState helpers
  • Saving list item back to SharePoint

When called with no parameters, it consumes the context from a parent <ListFormContext.Provider>.

Parameters

config?

IListFormConfig

Optional configuration used to initialize the form context. Must be provided at the root level.

Returns

IListFormContext

An instance of IListFormContext providing access to form state, validation, and persistence APIs.

Throws

Error if no config is passed and no parent context is available.

Examples

Initializing the listFormContext

const ctx = useListFormContext({
sp,
listName: 'Projects',
itemId: 5,
webPartContext,
onInit: async (ctx) => {
ctx.formState.setText('Title', 'Initial Value');
}
});

Consuming the list formContext

useListFormContext()