-
Notifications
You must be signed in to change notification settings - Fork 5
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
How to fix Replacing an existing Haven instance. Are you sure this behaviour is intended?
#142
Comments
Hey, What exactly is your use case here, i.e. how are you getting to the point that you have multiple conflicting |
Hi, Thank you for getting back. import { askUserConsent } from '@libs/askUserConcent'
useEffect(() => {
// Init analytics
askUserConsent(locale)
}, [])
// /libs/askUserConcent.ts
export const askUserConsent = (lang: string): void => {
const havenInstance = Haven.getInstance()
if (!havenInstance) {
Haven.create({
lang,
services: [
{
name: 'PostHog',
purposes: ['analytics'],
inject: () => {
analytics.enable()
},
},
],
notification: {
policyUrl: '/privacy-policy',
position: 'bottom',
styles: {
background: '#000',
textColor: '#A0AEC0',
linkColor: '#07C969',
buttonBackgroundColor: '#07C969',
buttonBackgroundColorHover: '#0D9347',
buttonTextColor: '#000',
},
},
translations: {
fr: {
notification: {
accept: 'Accepter',
decline: 'Refuser',
message: 'Message',
policy: 'Politique',
},
preferences: {
description: 'Description',
save: 'Sauvegarder',
saved: 'Sauvegardé',
},
purposes: {},
},
},
})
}
} However if I don't check if an instance already exists, then it will create new ones. I was wondering it this could be something that the library could handle since we aren't supposed to create multiple instances, instead of simply warn the user to actually return the existing instance. Thank you |
Hi,
First of all, a big thank you for creating this package. It's really helpful.
I'd like to know if it would be possible for you to instead of
console.warn("Replacing an existing Haven instance. Are you sure this behaviour is intended?");
if you could simply return the existing instance.create would be like this
If we have already an instance then there's no point in creating a new one right?
In my code I'm doing
But now I'm getting a console error because
getInstance()
has thisconsole.error("No Haven instance found. Make sure to create a Haven instance before attempting to access it.")
Thank you
The text was updated successfully, but these errors were encountered: