pnp-react-hooks
TypeScript icon, indicating that this package has built-in type declarations

1.3.0 • Public • Published

PnP React Hooks

PnP React Hooks is a wrapper library for PnPjs, provides configurable React hooks for SharePoint Rest API.

Usage:

import * as React from "react";
import { useListItems, useCurrentUser } from "pnp-react-hooks";

export const ExampleComponent = () => {

	const currentUser = useCurrentUser();

	const items = useListItems("My List", {
		query: {
			select: ["Title", "Id", "Author/Title"],
			expand: ["Author"],
			filter: `Author eq ${currentUser?.Id}`
		},
		disabled: !currentUser
	});

	return (<ul> { items?.map(item => (<li key={item.Id}>{item.Title}</li>)) } </ul>);
};

Installation

Npm v7+

npm install pnp-react-hooks

Npm v3-6

You have to install peer dependencies manually when using older npm versions.

npm install pnp-react-hooks @pnp/sp react

Documentation

For more details see the docs site.

Disclaimer

PnP React Hooks library is an open source project under MIT license. It's NOT an official package distributed by Microsoft.

/pnp-react-hooks/

    Package Sidebar

    Install

    npm i pnp-react-hooks

    Weekly Downloads

    6

    Version

    1.3.0

    License

    MIT

    Unpacked Size

    218 kB

    Total Files

    183

    Last publish

    Collaborators

    • superior-one