I'm using the SPFx with React in Typescript and able to get the SPUser, but it only has a couple of fields like displayName, email, and loginName. Is there a way to get the Department of the user? Or do I have to use PNP-JS?
Example how I get the displayName: this.props.context.pageContext.user.displayName
Is there a way to get other fields of the user?
You could use REST api also.
Sample script:
this.context.spHttpClient.get(this.context.pageContext.web.absoluteUrl + `/_api/sp.userprofiles.peoplemanager/GetMyProperties`, SPHttpClient.configurations.v1)
.then((response: SPHttpClientResponse) => {
var data= response.json();
console.log(data);
});