Skip to content

Instantly share code, notes, and snippets.

@cwparsons
Created February 28, 2020 17:01
Show Gist options
  • Save cwparsons/e29374c3594970a43628b13e9a450dbe to your computer and use it in GitHub Desktop.
Save cwparsons/e29374c3594970a43628b13e9a450dbe to your computer and use it in GitHub Desktop.
Detect if an SharePoint Framework (SPFx) web part is in display mode or not, using TypeScript.
import { DisplayMode } from '@microsoft/sp-core-library';
import { BaseClientSideWebPart } from '@microsoft/sp-webpart-base';
import * as React from 'react';
import * as ReactDom from 'react-dom';
export default class SampleWebPart extends BaseClientSideWebPart<{}> {
public render() {
ReactDom.render(
<div>
{this.displayMode === DisplayMode.Edit ? <span>Edit mode</span> : null}
{this.displayMode === DisplayMode.Read ? <span>Read mode</span> : null}
</div>,
this.domElement
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment