tomwayson / esri-loader-hooks

Custom React hooks for using the ArcGIS API for JavaScript with esri-loader.

Home Page:https://esri-loader-hooks.netlify.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

registerOAuthInfos before Map creation

gavinr opened this issue · comments

I'd like the ability to create an OAuthInfo instance and pass it to IdentityManager via a call to registerOAuthInfos([]) before I use useWebMap(). This is currently impossible to do because I'd need to load the esri/identity/OAuthInfo and esri/identity/IdentityManager modules via loadModules which then puts my hook call within a callback which is not allowed (from React error: Error: Invalid hook call. Hooks can only be called inside of the body of a function component):

loadModules([
    'esri/identity/OAuthInfo',
    'esri/identity/IdentityManager',
  ]).then(function([OAuthInfo, esriId]) {
    // https://developers.arcgis.com/javascript/latest/sample-code/identity-oauth-basic/index.html
    var info = new OAuthInfo({
      appId: 'xyz123',
      popup: false,
    });
    esriId.registerOAuthInfos([info]);

    const [ref, view] = useWebMap('aaaaaaaaaaaaaaaaaaaaaaaaa');
  });

Potential Solutions

  1. Additional option to the existing hooks (ex: useWebMap('aaaaaaaaaaaaaaaaaaaaaaaaa', { oAuthInfos })
  2. add a new hook (ex: useIdentityManager()) as part of this repo

Other Discussion

new hook vs introducing new options prior discussion: #6 (comment)