Skip to content

Commit 040f79a

Browse files
thechriskentVesaJuvonen
authored andcommitted
Minor Grammatical Updates (SharePoint#713)
Also, fixed the tutorial link
1 parent 74eb9e6 commit 040f79a

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

docs/spfx/web-parts/basics/working-with-requestdigest.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
# Working with the original __RequestDigest
22

3-
There is a lot of code written to work with the classic SharePoint pages that you can use with the SharePoint Framework, but sometimes certain components or variables aren't there. One example is the __REQUESTDIGEST form field. In an ideal world, you wouldn't use a global variable to access the digest, you'd just use the updated **HttpRequest** object to make your SharePoint call, and it will handle all the digest / auth logic for you (including things like expired tokens). The [Connect your client-side web part to SharePoint (Hello world part 2)](https://github.com/SharePoint/sp-dev-docs/wiki/HelloWorld,-Talking-to-SharePoint) article shows you how to do this.
3+
There is a lot of code written to work with classic SharePoint pages that you can use with the SharePoint Framework, but sometimes certain components or variables aren't there. One example is the `__REQUESTDIGEST` form field. In an ideal world, you wouldn't use a global variable to access the digest, you'd just use the updated `HttpRequest` object to make your SharePoint call, and it will handle all the digest/auth logic for you (including things like expired tokens). The [Connect your client-side web part to SharePoint (Hello world part 2)](https://dev.office.com/sharepoint/docs/spfx/web-parts/get-started/connect-to-sharepoint) article demonstrates how to do this.
44

5-
However, if your existing code uses some older constructs, through the power of client side code and DOM manipulation, it's fairly easy to add these back to a page. The key is to hook into the **onInit** method in the base web part class, and pull the create the DOM element that you expect to be there. Here's an example that creates the __REQESTDIGEST form element.
5+
However, if your existing code uses some older constructs, through the power of client-side code and DOM manipulation, it's fairly easy to add these back to a page. The key is to hook into the `onInit` method in the base web part class and create the DOM element that you expect to be there. Here's an example that creates the `__REQUESTDIGEST` form element:
66

77
```JavaScript
88
public onInit<T>(): Promise<T>
99
{
1010
// does the digest exist?
1111
if ( !document.getElementById('__REQUESTDIGEST') )
1212
{
13-
// OK, the request digest does not exist. Let's create it.
13+
// OK, the request digest does not exist. Let's create it.
1414
// first, grab the digest value out of the contextWebInfo object (if it exists).
1515
var digestValue: string;
1616
try{
1717
digestValue = (window as any)._spClientSidePageContext.contextWebInfo.FormDigestValue;
1818
}
1919
catch (exception){
20-
// there is no digest on this page, so just return. This can easily happen on the local workbench
20+
// there is no digest on this page, so just return. This can easily happen on the local workbench
2121
return Promise.resolve();
2222
}
2323

2424
if (digestValue){
25-
// OK, now lets create the digest input form. It looks like this -
25+
// OK, now lets create the digest input form. It looks like this:
2626
// <input type="hidden" name="__REQUESTDIGEST" id="__REQUESTDIGEST" value="blahblahblahblahblahblah, July23 -0000 or something like that">
2727
const requestDigestInput: Element = document.createElement('input');
2828
requestDigestInput.setAttribute('type', 'hidden');
@@ -40,12 +40,12 @@ However, if your existing code uses some older constructs, through the power of
4040
}
4141
```
4242

43-
>**Note:** There is a better way to get the current digest value that will handle all of the caching / expiring / refetching / etc. Give this a try. You'll need to import digestCacheServiceKey and IDigestCache from sp-client-base
43+
>**Note:** There is a better way to get the current digest value that will handle all of the caching, expiring, refetching, etc. Give this a try (You'll need to import `digestCacheServiceKey` and `IDigestCache` from **sp-client-base**):
4444
4545
```JavaScript
4646
var digestCache:IDigestCache = this.context.serviceScope.consume(digestCacheServiceKey);
4747
digestCache.fetchDigest(this.context.pageContext.web.serverRelativeUrl).then((digest: string) => {
4848
// Do Something with the digest
4949
console.log(digest);
5050
});
51-
```
51+
```

0 commit comments

Comments
 (0)