PnP React Controls Part 11 – ListPicker


Hi everyone, this is part 11 of PnP React Controls Series. This post will explain the usage of the PnP ListPicker control. We will see how we can leverage this control on our SPFx projects and make use of the feature provided by this control. Thanks to the community.

About the Control

This control could be very useful for the users, when they tried to load the content dynamically from the lists based on the selection. They could also load the files based on the selected libraries. There are few properties we could leverage to fit our requirements. If there is a need to display the lists or libraries to the end users for choose, then this control would be the best fit.

Focus on the Code

You can refer Part 1 post on the creation of the SPFx project and installing all the dependencies. In addition to the dependencies mentioned in that post you have to install @pnp/sp – v3.5.1. You should also do some changes to the project files to make the pnpjs version 3 to work on SPFx 1.14.0. Please follow this link to do the changes.

Created a webpart named listPickerDemo. Below is the ListPickerDemo.tsx file.

import * as React from 'react';
import { FC, useState } from 'react';
import styles from './ListPickerDemo.module.scss';
import { IListPickerDemoProps } from './IListPickerDemoProps';
import { ListPicker } from "@pnp/spfx-controls-react/lib/ListPicker";

const ListPickerDemo: FC<IListPickerDemoProps> = (props) => {
    const {
    } = props;
    const [selList, setSelList] = useState<string | string[]>(undefined);
    const [selMultiList, setSelMultiList] = useState<string | string[]>(undefined);
    const [selDocLib, setselDocLib] = useState<string | string[]>(undefined);

    const _onSingleListPickerChange = (lists: string | string[]) => {

    const _onMultiListPickerChange = (lists: string | string[]) => {

    const _onDocLibPickerChange = (lists: string | string[]) => {

    return (
        <section className={`${styles.listPickerDemo} ${hasTeamsContext ? styles.teams : ''}`}>
            <div className={styles.welcome}>
                <img alt="" src={isDarkTheme ? require('../assets/welcome-dark.png') : require('../assets/welcome-light.png')} className={styles.welcomeImage} />
                <h3>PnP List Picker Demo</h3>
                    <p><b>Selected List:</b> {selList}</p>
                    <ListPicker context={props.context as any}
                        label="Select your list"
                        placeholder="Select your list"
                        onSelectionChanged={_onSingleListPickerChange} />
                    <p><b>Selected Lists:</b> {selMultiList}</p>
                    <ListPicker context={props.context as any}
                        label="Select your lists"
                        placeholder="Select your lists"
                        onSelectionChanged={_onMultiListPickerChange} />
                    <p><b>Selected Document Libraries:</b> {selDocLib}</p>
                    <ListPicker context={props.context as any}
                        label="Select your document libraries"
                        placeholder="Select your document libraries"
                        onSelectionChanged={_onDocLibPickerChange} />

export default ListPickerDemo;

Below are the updates done to the file.

  • Changed the class component to the react hooks
  • Created a method named _onSingleListPickerChange, _onMultiListPickerChange, _onDocLibPickerChange to get the information about the selected list.
  • Following are the properties of the control that allows us to customize based on our requirement
    • context – BaseComponentContext to load the folders from the library
    • label – string that appears on the UI
    • baseTemplate – Base template of the list to be populated. Please click here to see different list templates available in SharePoint.
    • includeHidden – Whether to display the hidden lists or not
    • contentTypeId – Display only the lists that has this content type id.
    • selectedList – Method that will be executed when the list(s) is selected. It will return the selected list ID alone.
    • multiSelect – Enable or disable multi selection
    • filter – Use OData query to filter the lists.

Reference URL

ListPicker – @pnp/spfx-controls-react

Sample Implementation


I hope you had learned something about one of the pnp control. There are lot to come in future.

Please free to post your comments and let me know if you want me to post article on any particular feature or plugins that relates to SharePoint. Thanks for your support.

sudharsank/pnpcontrols-demo: Demo project on different PnP React Controls. (

Happy Coding…


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s