I am very new to React, and I cannot seem to solve a simple problem. I am implementing the auth0 lock widget, and have imported it in my 'routes.js' as follows:

*routes.js*:

```
import {requireAuth} from './js/helpers/AuthService.js';

```

My AuthService.js does not have a constructor, it only contains declarations of functions, some of which must be exported. Snippet:

*AuthService.js*:

```
  const lock = new Auth0Lock(
  client_id,
  domain, {
    auth: {
      redirectUrl: `${window.location.origin}${LOGIN_ROUTE}`,
      responseType: 'token id_token',
        params: {
         scope: 'openid email' 
      },
    }
  }
);

const events = new EventEmitter();

lock.on('authenticated', authResult => {
  setAccessToken(authResult.accessToken);
  lock.getUserInfo(authResult.accessToken, (error, profile) => {
    if (error) { return setProfile({error}); }
    setProfile(profile);
    browserHistory.push(getNextPath());
    clearNextPath();
  });
});

export function login(options) {
  lock.show(options);

  return {
    hide() {
      lock.hide();
    }
  }
}
(etc.)

```

The only thing I want to achieve is to load the 'client\_id' and 'domain' variables through an API call, before everything else loads. So basically something like:

```
# fetch the config variables
fetch(url)
    .then(function(response) {
    if (response.status >= 400) {
       throw new Error("Bad response from server");
    }
    return response.json();
  })
  .then(function(data) {
     const client_id = data.client_id
     const domain = data.domain
  });

  # Proceed with normal flow
  const lock = new Auth0Lock(
  client_id,
  domain, {
    auth: {
      redirectUrl: `${window.location.origin}${LOGIN_ROUTE}`,
      responseType: 'token id_token',
        params: {
         scope: 'openid email' 
      },
    }
  }
);

```

The problem I have is that the fetch is an async call, so the other code does not wait for it to finish, which triggers errors in the rest of the code (client\_id and domain are undefined). 

I have read about the componentDidMount function, but it is always mentioned that this can be used to delay rendering. I have nothing to render, I just want to declare some functions. For this, I only need some constant variables to be set based on an API call. This can't be that had, but I cannot seem to find a good solution.