Skip to content

Commit 1aacc4b

Browse files
authored
Change SPComponentLoader section (#5254)
* Change SPComponentLoader section `SPComponentLoader` is now part of `@microsoft/sp-loader` module that should be installed implicitly. * Removed en-US locale from the url
1 parent 37e1aa8 commit 1aacc4b

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

docs/spfx/web-parts/guidance/connect-to-sharepoint-using-jsom.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,14 +375,23 @@ Having loaded the titles of SharePoint lists in the current site, the final step
375375

376376
![SharePoint Framework client-side web part showing titles of SharePoint lists in the current site](../../../images/tutorial-spjsom-web-part-list-titles.png)
377377

378-
Referencing SharePoint JSOM scripts declaratively as external scripts is convenient and allows you to keep your code clean. One disadvantage, however, is that it requires specifying absolute URLs to the location from which SharePoint JSOM scripts should be loaded. If you're using separate SharePoint tenants for development, testing, and production, it requires some additional work to change these URLs for the different environments accordingly. In such cases, you may consider referencing JSOM imperatively by using the [SPComponentLoader](https://docs.microsoft.com/javascript/api/sp-application-base) to load the scripts in the SPFx component's code.
378+
Referencing SharePoint JSOM scripts declaratively as external scripts is convenient and allows you to keep your code clean. One disadvantage, however, is that it requires specifying absolute URLs to the location from which SharePoint JSOM scripts should be loaded. If you're using separate SharePoint tenants for development, testing, and production, it requires some additional work to change these URLs for the different environments accordingly. In such cases, you may consider referencing JSOM imperatively by using the [SPComponentLoader](https://docs.microsoft.com/javascript/api/sp-loader/spcomponentloader) to load the scripts in the SPFx component's code.
379379

380380
## Reference JSOM imperatively
381381

382382
Another way to load JavaScript libraries in SharePoint Framework projects is to use the `SPComponentLoader`, a utility class provided with the SharePoint Framework designed to help you load scripts and other resources in your components. One benefit of using the `SPComponentLoader` over loading scripts declaratively is that it allows you to use server-relative URLs, which is more convenient when using different SharePoint tenants for the different stages of your development process.
383383

384384
For this portion of the tutorial, we'll be adjusting the code we created previously in the Declarative section.
385385

386+
### Install @microsoft/sp-loader Module
387+
`SPComponentLoader` is declared in a separate module `@microsoft/sp-loader` that should be installed to your project.
388+
389+
1. From the console, execute the following command within your project directory:
390+
391+
```sh
392+
npm install @microsoft/sp-loader --save
393+
```
394+
386395
### Declarative reference cleanup
387396

388397
If you followed the steps in the declarative reference sections earlier, you need to remove those references.

0 commit comments

Comments
 (0)