react-nativeasyncstorageflagsmith

initializing flagsmith library inside a function not working


I am trying to use this in my reactjs application: https://docs.flagsmith.com/clients/javascript/

The way it is initalized is as follows:

flagsmith
  .init({
    environmentID: Config.FLAGSMITH_ENVIRONMENT_ID
  })
  .then(() => {
    flagsmith.startListening(1000);
  })
  .catch((error) => {
    console.log(error)
  });

this one works well but I want to wrap it in a function and initalize it from one component only so I did:

function initFlagSmith(){
  flagsmith
  .init({
    environmentID: Config.FLAGSMITH_ENVIRONMENT_ID
  })
  .then(() => {
    flagsmith.startListening(1000);
  })
  .catch((error) => {
    console.log(error)
  });
   }

but that doesn't work with error u.getItem undefined. Looking at flagsmith, i see u.getItem but also AsyncStorage has the method as well.

any help?

Here is a repo: https://github.com/iconicsammy/flagsmithissue


Solution

  • This was down to a typo, raised a PR here. https://github.com/iconicsammy/flagsmithissue/pull/1