title: Create a singleton class with react native
body: <p>I found different topics explain how to create a singleton, but none of them worked for me. This is an example taken from this post</p>
  
  <pre><code>export default class Credentials {
  
      static myInstance = null;
  
      _userID = "";
  
      static getInstance() {
          if (myInstance == null) {
              myInstance = new Credentials();
          }
  
          return myInstance;
      }
  
      getUserID() {
          return this._userID;
      }
  
      setUserID(id) {
          this._userID = id;
      }
  }
  </code></pre>
  
  <p>when I call <code>Credentials.getInstance()</code> I get a warning </p>
  
  <blockquote>
    <p>Can't find variable myInstance</p>
  </blockquote>