I am experiencing unexpected behaviour with arrow functions in JavaScript.
microsoftTeams.initialize();
microsoftTeams.getContext((context) => {
this.user = context.loginHint!;
console.log("Arrow function called");
});
console.log("Outside of Arrow Function");
When executing this code inside a React Component's constructor, the code block enclosed in the arrow function is the last one to be called. Even functions called after completions of the construction such as componentDidMount()
are called earlier:
FetchFiles.tsx:21 Outside of Arrow Function
FetchFiles.tsx:28 Component did mount
FetchFiles.tsx:19 Arrow function called
I am wondering why the enclosed code block is not executed first. Is this the expected behaviour and if so, what am I missing here?