Skip to content

Commit 0ce5dd5

Browse files
maliksahilVesaJuvonen
authored andcommitted
Added a note re: Global variables (SharePoint#468)
Global variables is not best practice, anywhere! Until this article is revised to show another pattern, we should include this disclaimer.
1 parent 08547ab commit 0ce5dd5

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

docs/spfx/web-parts/guidance/share-data-between-web-parts.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ To improve the loading time of the page and decrease the traffic on your network
6464

6565
## Store the retrieved data in a globally-scoped variable
6666

67+
> Note. globally-scoped variables are generally a bad idea. But for illustration and simplicity purposes, we are using them here as "demo code". There are many patterns around this issue, including importing/exporting modules using TypeScript concepts.
68+
6769
Web parts built using the SharePoint Framework are isolated into separate modules. This way, one web part cannot directly access data and properties stored by another web part. One way to overcome this design characteristic and make data loaded by one web part available to other web parts on the page, is to assign the retrieved data to a globally-scoped variable.
6870

6971
Considering the data access service mentioned above, it would be changed as follows:
@@ -375,4 +377,4 @@ export default class RecentDocumentsWebPart extends BaseClientSideWebPart<IRecen
375377
}
376378
```
377379

378-
Even if there are multiple web parts on the page referencing the same service, its bundle will be downloaded only once and SharePoint Framework will create only one instance of the service on the page. This offers you a convenient mechanism for centralizing processing and storing data on a page. While working with SharePoint Framework services is more complex than the previously described approaches, it offers you a great benefit of isolating the data from other components on the page and better handling of its integrity.
380+
Even if there are multiple web parts on the page referencing the same service, its bundle will be downloaded only once and SharePoint Framework will create only one instance of the service on the page. This offers you a convenient mechanism for centralizing processing and storing data on a page. While working with SharePoint Framework services is more complex than the previously described approaches, it offers you a great benefit of isolating the data from other components on the page and better handling of its integrity.

0 commit comments

Comments
 (0)