Skip to main content
Version: 1.0.0

getSP

@spartanfx/react v1.0.0


@spartanfx/react / getSP

Function: getSP()

getSP(context?): SPFI

Retrieves or initializes a PnPjs SPFI instance for SharePoint REST API operations.

Parameters

context?

WebPartContext

Optional SPFx web part context. If provided, initializes or re-initializes the SPFI instance.

Returns

SPFI

A configured SPFI instance for interacting with SharePoint.

Remarks

  • The instance is created only once per provided SPFx context and reused afterwards.
  • Requires the @pnp/sp and @pnp/logging packages.
  • The instance is configured using the spSPFx behavior with the provided context.

Call this function with a WebPartContext during initialization. Subsequent calls without parameters return the same initialized instance.

Example

// Initialize SPFI instance
const sp = getSP(this.context);

// Query SharePoint lists
const lists = await sp.web.lists();

// Reuse previously initialized instance
const spInstance = getSP();