Hey guys, How are you doing? I have a question ab...
# ask-questions
w
Hey guys, How are you doing? I have a question about the server-side instance of the SDK on NextJS. I saw the example, and it's already working (Server and Client side). (I am not using the flags adapter because I was having an error when I was setting the env variable, it was always forcing me to have the default name of the env vars even if I was passing in the init. It was always saying that it was missing the: GROWTHBOOK_CLIENT_KEY). 1. If I need to check if a feature flag is one, I should always init the Growthbook class, check the feature flag, and then destroy? Can I have one instance as a singleton and import it? Is it a good practice or should I always initiate a new instance?
f
Hi Matheus
instantiation should be very quick, and you can check states for all flags if needed. One instance should be enough. You can just update the atttributes as needed
w
So I can make a singleton that stays a live the whole time. Don't need to instantiate and destroy every time I need, right?
f
yes, correct
1
w
Thanks @fresh-football-47124
@fresh-football-47124 I think I can't have a singleton because when I turn on or off the feature flag it is not updated on the code, always gets the old value. But if I initiate a new version every time I need to check if it's on I get the updated value
Should I keep the singleton and do a refresh every time I need to evaluate if a feature flag is on? Because from what I understood, on the server is basically what it will happen every time I initialize a new instance of the client and destroy