What is SharePoint Framework (SPFx)?
The SharePoint Framework is Microsoft's modern development model for extending SharePoint. SPFx enables developers to build web parts, extensions, and library components using familiar web technologies like TypeScript, React, and Node.js.
Why Choose SPFx?
Advantages Over Legacy Approaches
Compared to Add-ins:
- Runs in page context (no iframes)
- Better performance
- Seamless user experience
- Full access to page DOM
Compared to Classic Web Parts:
- Modern tool chain
- Client-side execution
- Works with modern pages
- Cloud-ready
When to Use SPFx
Good Fit:
- Custom data visualizations
- Integration with external APIs
- Line-of-business applications
- Enhanced user experiences
Consider Alternatives:
- Simple configurations → Power Apps
- Workflow automation → Power Automate
- Basic customization → JSON formatting
Development Environment Setup
Prerequisites
- Node.js (LTS version)
```bash
node -v # Should be v18.x or compatible
```
- Code Editor (VS Code recommended)
- Install SPFx extensions
- TypeScript support
- React snippets
- Yeoman Generator
```bash
npm install -g yo @microsoft/generator-sharepoint
```
Creating Your First Project
```bash
# Create project directory
mkdir my-webpart && cd my-webpart
# Run generator
yo @microsoft/sharepoint
# Answer prompts:
# - Solution name: my-webpart
# - SharePoint version: SharePoint Online only
# - Folder: current folder
# - Component type: WebPart
# - Web part name: HelloWorld
# - Framework: React
```
Project Structure
```
my-webpart/
├── config/
│ ├── config.json
│ ├── deploy-azure-storage.json
│ ├── package-solution.json
│ └── serve.json
├── src/
│ └── webparts/
│ └── helloWorld/
│ ├── HelloWorldWebPart.ts
│ ├── components/
│ │ ├── HelloWorld.tsx
│ │ └── HelloWorld.module.scss
│ └── loc/
│ └── mystrings.d.ts
├── teams/
├── gulpfile.js
├── package.json
└── tsconfig.json
```
Key Files
HelloWorldWebPart.ts: Main web part class
- Handles property pane
- Renders React component
- Manages lifecycle
HelloWorld.tsx: React component
- UI implementation
- Business logic
- Data fetching
package-solution.json: Deployment configuration
- Solution ID
- Feature definitions
- API permissions
Development Workflow
Local Development
```bash
# Start local workbench
gulp serve
# Opens: https://localhost:4321/temp/workbench.html
```
Testing on SharePoint
```bash
# Start with SharePoint workbench
gulp serve --nobrowser
# Navigate to:
# https://[tenant].sharepoint.com/_layouts/15/workbench.aspx
```
Building for Production
```bash
# Bundle solution
gulp bundle --ship
# Package solution
gulp package-solution --ship
# Output: sharepoint/solution/*.sppkg
```
Core Concepts
Web Part Properties
Define configurable properties:
```typescript
export interface IHelloWorldWebPartProps {
description: string;
listName: string;
itemCount: number;
}
```
Property Pane
Configure user settings:
```typescript
protected getPropertyPaneConfiguration() {
return {
pages: [{
groups: [{
groupFields: [
PropertyPaneTextField('description', {
label: 'Description'
}),
PropertyPaneDropdown('listName', {
label: 'Select List',
options: this.listOptions
})
]
}]
}]
};
}
```
SharePoint Context
Access SharePoint data:
```typescript
// Get current user
this.context.pageContext.user.displayName
// Get site URL
this.context.pageContext.web.absoluteUrl
// Use SP HTTP client
this.context.spHttpClient.get(url, SPHttpClient.configurations.v1)
```
Working with SharePoint Data
REST API Calls
```typescript
private async getListItems(): Promise
const response = await this.context.spHttpClient.get(
`${this.context.pageContext.web.absoluteUrl}/_api/web/lists/getbytitle('Tasks')/items`,
SPHttpClient.configurations.v1
);
const data = await response.json();
return data.value;
}
```
PnPjs Library
Simplified data access:
```typescript
import { spfi, SPFx } from "@pnp/sp";
import "@pnp/sp/webs";
import "@pnp/sp/lists";
const sp = spfi().using(SPFx(this.context));
const items = await sp.web.lists.getByTitle("Tasks").items();
```
Deployment
App Catalog Deployment
- Create tenant app catalog (if needed)
- Upload .sppkg file
- Deploy solution
- Add to sites
Site-Scoped Deployment
For specific sites only:
- Enable site-scoped deployment in manifest
- Upload to site collection app catalog
- Available only in that site collection
CDN Configuration
For production performance:
- Office 365 CDN (recommended)
- Azure CDN
- Custom CDN
Best Practices
Performance
- Lazy load components
- Minimize bundle size
- Use code splitting
- Cache data appropriately
Security
- Never store secrets in code
- Use Azure AD for authentication
- Validate all inputs
- Follow least privilege principle
Maintenance
- Version your components
- Document dependencies
- Automated testing
- CI/CD pipeline
Troubleshooting
Common Issues
Build Errors:
- Check Node.js version
- Clear npm cache
- Delete node_modules and reinstall
Runtime Errors:
- Check browser console
- Verify API permissions
- Test in workbench first
Deployment Issues:
- Verify app catalog permissions
- Check package-solution.json
- Review deployment logs
Conclusion
SPFx opens powerful customization possibilities for SharePoint. Start with simple web parts, learn the patterns, and gradually tackle more complex scenarios. The combination of modern web technologies and SharePoint integration creates opportunities for truly custom experiences.
Need help building custom SPFx solutions? Our development team can create tailored web parts and extensions for your organization.
Written by Errin O'Connor
Founder, CEO & Chief AI Architect | Microsoft Press Bestselling Author | 25+ Years Microsoft Ecosystem
Errin O'Connor is a Microsoft Press bestselling author of 4 books covering SharePoint, Power BI, Azure, and large-scale migrations. He leads our SharePoint consulting practice with expertise spanning 500+ enterprise migrations and compliance implementations across HIPAA, SOC 2, and FedRAMP environments.
Expert SharePoint Services
Need Expert Help?
Our SharePoint consultants are ready to help you implement these strategies in your organization.