SharePoint Framework (SPFx) Learning Guide
Tags: sharepointonline, microsoftteams, learning, react
Published: 2024-01-24 16:26:15

---
title: SharePoint Framework (SPFx) Learning Guide
published: true
date: 2022-05-09 16:50:20 UTC
tags: SharePointOnline,MicrosoftTeams,learning,React
canonical_url: https://blogit.create.pt/miguelisidoro/2022/05/09/sharepoint-framework-spfx-learning-guide/
---

Hello,

Are you new to SharePoint or do you just want to learn how to develop SharePoint modern solutions? Then, you came to the right place!

This is a guide to help you learn SharePoint Framework (SPFx), a framework to develop SharePoint (and Teams) client-side solutions. SPFx leverages the following technologies:

- [React ](https://reactjs.org/)/ [Angular](https://angular.io/)
- [TypeScript](https://www.typescriptlang.org/)
- [SharePoint Online](https://www.microsoft.com/pt-pt/microsoft-365/sharepoint/collaboration)
- [Microsoft Teams](https://www.microsoft.com/en-us/microsoft-teams/group-chat-software/)

## The Basics

[SharePoint Framework](https://docs.microsoft.com/en-us/sharepoint/dev/spfx/sharepoint-framework-overview) is a  **page and web part model ** that provides full support for ** client-side SharePoint development** ,  **easy integration with SharePoint data** , and  **extending**   **Microsoft Teams.**  With the SharePoint Framework, you can use modern web technologies and tools in your preferred development environment to build productive experiences and apps that are responsive and mobile-ready.

The SPFx is the recommended SharePoint customization and extensibility model for developers. Due to tight integration between SharePoint Online, Microsoft Teams, and Microsoft Viva Connections, developers can also use SPFx to customize and extend all these products. In fact, SPFx is the only extensibility and customization option for Viva Connections.

In addition to SharePoint Online, SPFx is supported and can be used to customize SharePoint on-premises deployments going back to SharePoint Server 2016.

With the SharePoint Framework, we can develop:

- [Web Parts](https://docs.microsoft.com/en-us/sharepoint/dev/spfx/web-parts/overview-client-side-web-parts)
- [Extensions](https://docs.microsoft.com/en-us/sharepoint/dev/spfx/extensions/overview-extensions)
- [Library components](https://docs.microsoft.com/en-us/sharepoint/dev/spfx/library-component-overview)
- [Adaptive Card Extensions](https://docs.microsoft.com/en-us/sharepoint/dev/spfx/viva/get-started/build-first-sharepoint-adaptive-card-extension)

Other useful links:

- [Overview of the SharePoint Framework (SPFx)](https://docs.microsoft.com/en-us/sharepoint/dev/spfx/sharepoint-framework-overview)
- [Scaffold projects by using Yeoman SharePoint generator](https://docs.microsoft.com/en-us/sharepoint/dev/spfx/toolchain/scaffolding-projects-using-yeoman-sharepoint-generator)
- [SharePoint Framework development tools and libraries](https://docs.microsoft.com/en-us/sharepoint/dev/spfx/tools-and-libraries)
- [SharePoint Framework toolchain](https://docs.microsoft.com/en-us/sharepoint/dev/spfx/toolchain/sharepoint-framework-toolchain)

### Technology stack

![](https://blogit.create.pt/wp-content/uploads/2022/05/sharepoint_framework_logo.jpg)
_SPFx Technology stack_

### SPFx Development Toolchain

![](https://blogit.create.pt/wp-content/uploads/2022/05/spfx-development-toolchain-1-1.png)
_SPFx Development Toolchain_

## TypeScript

[TypeScript ](https://www.typescriptlang.org/)is the preferred programming language to develop in SPFx. TypeScript is a programming language and maintained by Microsoft and is a superset of JavaScript and adds optional static typing to the language to develop client-side solutions. It is designed for the development of large applications and transpiles to JavaScript to be executed in the browser.

Useful TypeScript concepts:

- [const](https://www.typescriptlang.org/docs/handbook/variable-declarations.html) – allows the definition of a variable whose value is not going to be changed. Use this instead of let if the variable value is not going to be changed after its declaration.
- [let](https://www.typescriptlang.org/docs/handbook/variable-declarations.html) – allows the definition of a variable whose value is going to be changed. Use this instead of const if the variable value is going to be changed after its declaration.
- [var ](https://www.typescriptlang.org/docs/handbook/variable-declarations.html)– allows the definition of a variablewhose value is going to be changed. To be  **avoided ** since variables declared with var are acessible from any scope (scope (function, module, namespace, global)
- [type](https://javascript.plainenglish.io/when-to-best-use-type-class-or-interface-in-typescript-73bf66de19e9) – allows the definition of a data class without any business logic or methods, just data. It can be also useful to avoid the usage of magic strings in the code.
- [enum](https://javascript.plainenglish.io/when-to-best-use-type-class-or-interface-in-typescript-73bf66de19e9) – allows the definition of a enumeration
- [interface ](https://javascript.plainenglish.io/when-to-best-use-type-class-or-interface-in-typescript-73bf66de19e9)– allows the definition of a interface that can then be implemented by a concret class.
- [class](https://javascript.plainenglish.io/when-to-best-use-type-class-or-interface-in-typescript-73bf66de19e9) – allows the definition of a class that optionally implements an interface
- [extends ](https://www.typescriptlang.org/docs/handbook/2/classes.html)– when used it allows create a class that inherits from another class
- [export ](https://www.typescriptlang.org/docs/handbook/modules.html#export)– allows the export ** ** of functions, variables, interfaces and classes that can be imported with the import statement
- [import](https://www.typescriptlang.org/docs/handbook/modules.html#import) – allows the import of functions, variables, interfaces and classes exported with the export statement

Useful links:

- [The starting point for learning TypeScript](https://www.typescriptlang.org/docs/)
- [TypeScript for the New Programmer](https://www.typescriptlang.org/docs/handbook/typescript-from-scratch.html)
- [TypeScript Tutorials](https://www.tutorialsteacher.com/typescript)
- [Clean Code concepts adapted for TypeScript](https://github.com/labs42io/clean-code-typescript)

## React

[React](https://reactjs.org/)is a JavaScript library for building user interfaces and is at the core of SPFx to build advanced applications.

- **Declarative:**  React makes it painless to create interactive UIs. Design simple views for each state in your application and React will efficiently update and render just the right components when your data changes. Declarative views make your code more predictable, simpler to understand, and easier to debug.
- **Component-Based:**  Build encapsulated components that manage their state, then compose them to make complex UIs. Since component logic is written in JavaScript instead of templates, you can easily pass rich data through your app and keep the state out of the DOM.
- **Learn Once, Write Anywhere:**  We don’t make assumptions about the rest of your technology stack, so you can develop new features in React without rewriting existing code. React can also render on the server using Node and power mobile apps using [React Native](https://reactnative.dev/).

Useful links:

- [React Official Web Site](https://reactjs.org)
- [Tutorial: Intro to React](https://reactjs.org/tutorial/tutorial.html)
- [React Component LifeCycle](https://reactjs.org/docs/react-component.html#the-component-lifecycle)
- [How to get started with React for building advanced SPFx solutions](https://laurakokkarinen.com/how-to-get-started-with-react-for-building-advanced-spfx-solutions/)
- [SharePoint Online: CRUD operations using SPFx ReactJS framework](https://global-sharepoint.com/sharepoint-online/sharepoint-online-crud-operations-using-spfx-reactjs-framework/)
- [How to React ⚛️](https://kentcdodds.com/blog/how-to-react)
- [Fluent UI (Microsoft Components for Microsoft 365 Applications)](https://developer.microsoft.com/en-us/fluentui)
- [React: Lists and Keys](https://reactjs.org/docs/lists-and-keys.html)

To help developers to build advanced SPFx solutions, there are a lot of React controls, either developed by Microsoft such as [Fluent UI](https://developer.microsoft.com/en-us/fluentui) or by communities such as the [PnP community](https://pnp.github.io/).

## PnP JS

[PnP JS](https://pnp.github.io/pnpjs/) is a NPM package that simplifies interaction with SharePoint Online and Microsoft Graph.

Useful links:

- [Working with SharePoint List Items](https://pnp.github.io/pnpjs/sp/items/)
- [Use @pnp/sp (PnPJS) library with SharePoint Framework web parts](https://docs.microsoft.com/en-us/sharepoint/dev/spfx/web-parts/guidance/use-sp-pnp-js-with-spfx-web-parts)
- [A Complete Guide to Getting and Setting Fields Value using PnP JS in SPFx](https://ravichandran.blog/2020/06/24/a-complete-guide-to-getting-and-setting-fields-value-using-pnp-js-in-spfx/)
- [Using PnP JS with Microsoft Graph](https://pnp.github.io/pnpjs/packages/#graph)
- [PnP SDKs](https://pnp.github.io/#sdks)

## Repositories

Here are some of the most useful repositories to start learning SharePoint Framework:

- [Microsoft 365 Community](https://github.com/pnp)
- [Microsoft 365 Community Repositories](https://github.com/orgs/pnp/repositories?q=spfx&type=all&language=&sort=%20-%C2%A0)
- [SharePoint Framework web part, Teams tab, personal app, app page samples](https://github.com/pnp/sp-dev-fx-webparts%20-%20pnp/sp-dev-fx-webparts)
- [Reusable React controls for SPFx solutions](https://github.com/pnp/sp-dev-fx-controls-react%20-%20pnp/sp-dev-fx-controls-react)
- [sp-dev-fx-webparts](https://github.com/pnp/sp-dev-fx-webparts)
- [pnp/sp-dev-fx-extensions](https://github.com/pnp/sp-dev-fx-extensions)
- [pnp/sp-dev-fx-property-controls](https://github.com/pnp/sp-dev-fx-property-controls)
- [pnp/sp-dev-fx-aces](https://github.com/pnp/sp-dev-fx-aces)
- [Microsoft 365 Unified Sample Gallery with more than 1000 samples](https://devblogs.microsoft.com/microsoft365dev/announcing-new-microsoft-365-unified-sample-gallery-with-more-than-1000-samples/)

## Concepts / Tooling

### Core SPFx Concepts

- [JavaScript frameworks](https://docs.microsoft.com/en-us/sharepoint/dev/spfx/tools-and-libraries#javascript-frameworks)
- [Node.js](https://docs.microsoft.com/en-us/sharepoint/dev/spfx/tools-and-libraries#nodejs)
- [NPM (Node Package Manager)](https://docs.microsoft.com/en-us/sharepoint/dev/spfx/tools-and-libraries#node-package-manager-npm)
- [Yeoman](https://docs.microsoft.com/en-us/sharepoint/dev/spfx/tools-and-libraries#yeoman-generators)
- [Gulp](https://docs.microsoft.com/en-us/sharepoint/dev/spfx/tools-and-libraries#gulp-task-runner)
- [WebPack](https://docs.microsoft.com/en-us/sharepoint/dev/spfx/tools-and-libraries#webpack)

### NPM Packages

SharePoint client-side development tools use the [npm](https://www.npmjs.com/) package manager, like [NuGet](https://www.nuget.org/), to manage dependencies and other required JavaScript helpers. npm is typically included as part of Node.js setup.

Package installation modes:

- **npm install @package** – installs the package
- **npm install @package –save** – installs the package and updates package.json automatically (dependencies section)
- **npm install @package@version –save-dev** – installs the package and updates package.json automatically (devDependencies section)
- **npm install @package@version –save** – installs the package with the specified version and updates package.json automatically (dependencies section)
- **npm install @package@version –save-dev** – installs the package with the specified version and updates package.json automatically (devDependencies section)

Useful npm packages to include in a SPFx solution:

- **npm install gulp yo @microsoft/generator-sharepoint –global**
- **npm install @microsoft/microsoft-graph-types –save**
- **npm install @pnp/sp –save**
- **npm install @pnp/graph –save**
- **npm install @fluentui/react –save**
- **npm install @pnp/spfx-controls-react –save**
- **npm install @pnp/spfx-property-controls –save**
- **npm install localforage  –save**
- **npm install @luudjanssen/localforage-cache –save**
- **npm install spfx-fast-serve -g**

### Gulp Commands

- **gulp clean** – cleans the solution. Cleans the dist and temp folders from the solution
- **gulp trust-dev-cert** – installs the development certificate
- **gulp build** – builds the solution, tranforms TypeScript into JavaScript
- **gulp bundle** – bundles the solution and minimizes CSS and JS (in debug mode)
- **gulp bundle –ship** – bundles the solution and minimizes CSS and JS for deployment in SharePoint in production mode (release mode)
- **gulp package-solution** – generates package (.sppkg file) but to run in debug mode
- **gulp package-solution –ship** – generates package (.sppkg file) to run in production mode
- **gulp serve** – launches SharePoint Workbench to test web parts in debug mode
- **gulp serve –nobrowser** – allows testing web parts in debug mode but without launching SharePoint Workbench

## SPFx Development Environment

### Setup Development Environment

To [setup your development environment](https://docs.microsoft.com/en-us/sharepoint/dev/spfx/set-up-your-development-environment), run the following commands from the command prompt:

- npm install gulp-cli yo @microsoft/generator-sharepoint –global
- npm install webpack –global
- npm install –save-dev webpack
- gulp trust-dev-cert

### Node Version Manager (nvm)

Node Version Manager (NVM) allows developers to install multiple versions of node. This can be useful when working with different SPFx versions that use different versions of Node.

To download NVM, click [here](https://github.com/coreybutler/nvm-windows/releases).

#### Install Node using NVM

After installing NVM, to install a node version use the following command:

nvm install <node\_version>. Example: nvm install 14.19.1

#### Switch between versions of Node

If you have multiple versions of Node, you can switch between them using the following command:

nvm use <node\_version>. Example: nvm use 12.22.10

To have a full list of the installed node versions, run “nvm list”.

### SPFx Fast Serve

If you have a big SPFx solution, gulp serve can take a lot of time, especially if you want to rapidly test your developments. SPFx Fast Serve is a command line utility, which modifies your SharePoint Framework solution, so that it runs continuous serve command as fast as possible. To know more, click [here](https://github.com/s-KaiNet/spfx-fast-serve). 

Here is a comparison between gulp serve and SPFx Fast Serve (times depend on hardware, environment). The times listed below are “refresh” time (the time needed to compile your project when you change a file and start refreshing a page in a browser):

| | gulp serve | spfx-fast-serve |
| --- | --- | --- |
| Default “Hello World”  
React web part | 3-5 sec | 0.1-0.2 sec |
| [PnP Modern Search solution](https://github.com/microsoft-search/pnp-modern-search) | 28-34 sec | 2-4 sec |
| [SP Starter Kit solution](https://github.com/SharePoint/sp-starter-kit) (v1) | 40-50 sec | 2-3 sec |

This is a must have for every SharePoint Framework Developer!

### Recommended Visual Studio Code Extensions

- [Auto Rename Tag](https://marketplace.visualstudio.com/items?itemName=formulahendry.auto-rename-tag)
- [Tabnine](https://www.tabnine.com/install/vscode)
- [VSCode icons](https://marketplace.visualstudio.com/items?itemName=vscode-icons-team.vscode-icons)
- [Bracket Pair Colorizer](https://marketplace.visualstudio.com/items?itemName=CoenraadS.bracket-pair-colorizer) 
- [Visual Code IntelliCode](https://marketplace.visualstudio.com/items?itemName=VisualStudioExptTeam.vscodeintellicode) 
- [SonarLint for Visual Studio Code](https://www.sonarlint.org/vscode) 
- [PowerShell](https://marketplace.visualstudio.com/items?itemName=ms-vscode.PowerShell) 
- [Live Server](https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer)
- [Glean](https://marketplace.visualstudio.com/items?itemName=wix.glean)
- [Thunder Client](https://marketplace.visualstudio.com/items?itemName=rangav.vscode-thunder-client)
- [SPFx Snippets](https://marketplace.visualstudio.com/items?itemName=eliostruyf.spfx-snippets)

## SPFx Quick Start

The most common development component in SPFx is the web part. To better understand how to create your first web part, read [this article](https://laurakokkarinen.com/how-to-get-started-with-react-for-building-advanced-spfx-solutions/). In SPFx client-side web parts, we have the following components:

- Web part main component – acts as a container to the React component that has the main logic. In this example, we have a web part class called  **BirthdaysWorkAnniversariesNewCollaboratorsWebPart ** that renders the  **BirthdaysWorkAnniversariesNewCollaborators ** React component that has the web part main logic.

![](https://blogit.create.pt/wp-content/uploads/2022/05/spfx_webpart-1024x532.png)

- React component associated with the web part. This file has a  **render ** method responsible for the rendering of the web part UI and uses two major React concepts:  **props ** supplied by the web part that allows users to configure the web part behavior and  **state**  that also allows to control how the the web part is rendered. The main difference between props and state is that state can be changed and props can’t (in the code they are readonly). In the example below, we have the  **BirthdaysWorkAnniversariesNewCollaborators ** React component that was called by the  **BirthdaysWorkAnniversariesNewCollaboratorsWebPart ** web part.

![](https://blogit.create.pt/wp-content/uploads/2022/05/spfx_component-1024x694.png)

- Other associated files such as: 
  - Service classes to get data from SharePoint or Microsoft Graph for instance
  - Data object classes (models)
  - Helper classes

  - etc

## SPFx Tutorials

### Getting Started with SPFx

- [SharePoint Framework Tutorial 1 – HelloWorld WebPart](https://www.youtube.com/watch?v=6WTtjXP5yW4&list=PLR9nK3mnD-OXvSWvS2zglCzz4iplhVrKq&index=3)
- [SharePoint Framework Tutorial 2 – HelloWorld, Talking to SharePoint](https://www.youtube.com/watch?v=5M3zDpgxIMs&list=PLR9nK3mnD-OXvSWvS2zglCzz4iplhVrKq&index=4)
- [SharePoint Framework Tutorial 3 – HelloWorld, Serving in SharePoint Page](https://www.youtube.com/watch?v=FkFg32NSTM0&list=PLR9nK3mnD-OXvSWvS2zglCzz4iplhVrKq&index=5)
- [SharePoint Framework Tutorial 4 – HelloWorld, Deploy to Office 365 CDN](https://www.youtube.com/watch?v=N-KowN-UwTM&list=PLR9nK3mnD-OXvSWvS2zglCzz4iplhVrKq&index=6)
- [SharePoint Framework Tutorial – Using Microsoft Graph APIs](https://www.youtube.com/watch?v=tHzbh5JoC-A&list=PLR9nK3mnD-OXvSWvS2zglCzz4iplhVrKq&index=8)
- [SharePoint Framework Tutorial – Surfacing your solution as a Microsoft Teams tab](https://www.youtube.com/watch?v=JoTAC2i-XeU&list=PLR9nK3mnD-OXvSWvS2zglCzz4iplhVrKq&index=8)
- [SharePoint Framework Tutorial – Using Office UI Fabric React Components](https://www.youtube.com/watch?v=kNrYd8nYaZY&list=PLR9nK3mnD-OXvSWvS2zglCzz4iplhVrKq&index=10)
- [SharePoint Framework Tutorial – Provisioning SharePoint assets from SPFx solution](https://www.youtube.com/watch?v=09uoG6Voeew&list=PLR9nK3mnD-OXvSWvS2zglCzz4iplhVrKq&index=11)
- [SharePoint Framework Tutorial – Create a Full Width Web Part Page with SPFx](https://www.youtube.com/watch?v=8BATz6LD6tA)
- [Debugging SharePoint Framework solutions in  Visual Studio Code](https://www.youtube.com/watch?v=oNChcluMrm8)
- [Work with SharePoint Content using the SharePoint Framework](https://docs.microsoft.com/en-us/learn/modules/sharepoint-spfx-spcontent/)

### Developing SPFx Extensions

- [SharePoint Framework Extensions Tutorial 1 – Build your first Extension](https://www.youtube.com/watch?v=DnfRIl2YN8g&list=PLR9nK3mnD-OXtWO5AIIr7nCR3sWutACpV&index=2)
- [SharePoint Framework Extensions Tutorial 2 – Using page placeholders from Application Customizer](https://www.youtube.com/watch?v=Wm1PG8U5bSw&list=PLR9nK3mnD-OXtWO5AIIr7nCR3sWutACpV&index=2)
- [SharePoint Framework Extensions Tutorial 3 – Deploy your extension to site collection](https://www.youtube.com/watch?v=tReoZGtAYB4&list=PLR9nK3mnD-OXtWO5AIIr7nCR3sWutACpV&index=3)
- [SharePoint Framework Extensions Tutorial 4 – Hosting extension from Office 365 CDN](https://www.youtube.com/watch?v=xsZbRliakyM&list=PLR9nK3mnD-OXtWO5AIIr7nCR3sWutACpV&index=4)
- [SharePoint Framework Extensions Tutorial – Build your first Field Customizer](https://www.youtube.com/watch?v=mBZ7Sq_KfDA&list=PLR9nK3mnD-OXtWO5AIIr7nCR3sWutACpV&index=5)
- [SharePoint Framework Extensions Tutorial – Build your first ListView Command Set](https://www.youtube.com/watch?v=uaUGtLrNbRA&list=PLR9nK3mnD-OXtWO5AIIr7nCR3sWutACpV&index=6)

### SharePoint CRUD Operations with SPFx

- [SharePoint List Items CRUD Operations Demo Using PnPJS In React based SPFx Webpart](https://www.c-sharpcorner.com/article/sharepoint-list-items-crud-operations-demo-using-pnpjs-in-react-based-spfx-webpa/)
- [SharePoint CRUD Sample with Details List Fluent UI Control and a SharePoint List](https://github.com/miguelisidoro/SharePoint/tree/master/SPFx/react-detailslist)

The post [SharePoint Framework (SPFx) Learning Guide](https://blogit.create.pt/miguelisidoro/2022/05/09/sharepoint-framework-spfx-learning-guide/) appeared first on [Blog IT](https://blogit.create.pt).