title: Storing current logged in userId in a variable using React SPFx
body: <p>I am new to SPFx and wrapping my head around getting the current logged in user on SPFx using React , I did refer to a few posts here , However couldn't find the resolution I've been looking for.</p>
  <p>My end goal is to get the current logged in userID and store the value in a variable to be used in RestAPI later</p>
  <p>Below is the code sample</p>
  <pre class="lang-js prettyprint-override"><code>public componentdidmount() {
    var u;
    sp.web.currentUser.get().then(
      (user) =&gt; {
        console.log(user);
        u = user.UserId;
      },
      (errorResponse) =&gt; {
        debugger;
        console.log(errorResponse);
      }
    ); //Get Current User*/
  
    sp.web.lists
      .getByTitle(&quot;SampleList&quot;)
      .items.select(
        &quot;*&quot;,
        &quot;CourseName/Title&quot;,
        &quot;Attendee/Title&quot;,
        &quot;Attendee/ID&quot;,
        &quot;Status/Title&quot;,
        &quot;Completed&quot;,
        &quot;AttachmentFiles&quot;
      )
      .expand(&quot;CourseName&quot;, &quot;Attendee&quot;, &quot;Status&quot;, &quot;AttachmentFiles&quot;)
      .filter(&quot;Status/Title eq 'Not Started' and Attendee eq '&quot; + u + &quot;'&quot;)
      .top(4999)
      .orderBy(&quot;Created&quot;, false)
      .get()
      .then((response) =&gt; {
        let getdetails = response.map((item) =&gt; new EntityListItems(item));
      });
  }
  </code></pre>
  <p>While debugging , I get an undefined value on the variable u.</p>
  <p>I would be grateful if someone could help me with storing the current logged in userID to a variable so that I can pass the value to the Rest call.</p>
  <p>Any help would be appreciated.</p>