-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
init() to gurantee Flagsmith won't be reinitialized more than once? #77
Comments
Hi @sammysium - @kyle-ssg will be along soon to answer this! In the meantime - I don't see your Q on Stack Overflow? Did you remove it? |
Hey @sammysium it's a bit difficult to piece together a full example from the above. Are you able to make a quick gist or repo separating into files as to what you've tried? I can't see a good reason for wrapping the init function to cause an issue, I suspect something else is going on to cause that issue. Actually are you sure AsyncStorage is defined and has a function getItem? It seems like the error is around that. |
Ah, I think you need to pass AsyncStorage into init, not asyncStorage.
|
@kyle-ssg actually I thought AsyncStorage is the issue as well (removed it even just to see a change). import AsyncStorage from '@react-native-community/async-storage'; so yeah I am using that one as well. Hold on, I will create a small repo. |
like i said, outside the function it works just great. |
@kyle-ssg sorry for delay. Here is the repo: https://github.com/iconicsammy/flagsmithissue strangely enough, i cant get it to work with or without a wrapper this time in this mini-repo but the error message is the same. in my real app, I get the error only if I wrap it into a function. here is screenshot of the erro as well |
@kyle-ssg any thoughts please on why I am getting .getItem error? |
@sammysium in this repository you're still initialising flagsmith with asyncStorage instead of AsyncStorage as previously mentioned. Changing it to AsyncStorage instead of asyncStorage works fine for me inside your initializeFlagSmith function.
Added PR. |
already asked on SO but didn't get a reply. so sorry for spamming it here. Basically, we want to create a wrapper for FS since our need differs:
all is good so far but I was wondering why I can't wrap the initalization in a function because I want to manually. Sure, I can do the init() in the component but I want to keep all flagsmith related tasks in the file. So, I tried the following but it returns two errors randomly:
one of the errors is 'u.getItem' (u is undefined) and another one flags is undefined. Why does it not initialize when I wrapped it in a function but does get initalized outside of the function?
The text was updated successfully, but these errors were encountered: