When developing solutions with the SharePoint Framework (SPFx), it is often necessary to provide users with a way to select a SharePoint site. This capability is important in scenarios such as pulling information from different sites, aggregating reports, or provisioning resources to specific locations.

The PnP Site Picker control, available in the PnP SPFx React Controls library, is a ready-to-use component designed to address this exact need. Instead of building custom dropdowns or requiring users to type URLs manually, this control provides a simple, intuitive, and reliable interface for site selection.

What is the Site Picker Control?

The Site Picker control is a React-based user interface element that integrates seamlessly with SPFx. It allows users to search for and select one or more SharePoint sites directly from their tenant.

Key Features

Why Should You Use It?

Without this control, developers often end up creating custom dropdowns or maintaining lists of site URLs, which can be error-prone and time-consuming. The Site Picker control solves these issues by offering:

How to Use the Site Picker

Step 1. Install the Required Package

The Site Picker is part of the PnP SPFx React Controls library. Install it in your project with:

npm install @pnp/spfx-controls-react --save

Step 2. Import the Control

Add the following import statement in your component file:

import { SitePicker } from "@pnp/spfx-controls-react/lib/SitePicker";

Step 3. Implement the Control

Here is a basic example of the Site Picker in action:

<SitePicker
  label="Select Site(s)"
  context={this.props.context}
  mode="site"
  multiSelect={true}
  onChange={(sites) => {
    console.log("Selected sites:", sites);
    this.setState({ selectedSites: sites });
  }}
/>

Explanation of Properties

Example Use Cases

Best Practices

Conclusion

The PnP Site Picker control is a valuable tool for developers working with SPFx. It eliminates the need for custom site selection components, reduces complexity, and provides users with a modern, intuitive experience. By leveraging this control, you can focus more on the business logic of your solution while ensuring that site selection remains seamless and reliable.

If your SPFx project involves working across multiple SharePoint sites, the Site Picker control is highly recommended.