Skip to content
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

[Suggestion] useScript #203

Closed
curtvict opened this issue Sep 2, 2022 · 1 comment
Closed

[Suggestion] useScript #203

curtvict opened this issue Sep 2, 2022 · 1 comment

Comments

@curtvict
Copy link
Contributor

curtvict commented Sep 2, 2022

I'm curious if the community would find this change to the call signature of useScript at all useful:

function useScript(src: string, shouldLoad: boolean = true, removeOnUnmount: boolean = false): Status { ... }

shouldLoad could be used for something, like, an environment or privacy flag:

useScript('//some-script.js', isProduction) // or
useScript('//some-script.js', !isTest) // or
useScript('//some-script.js', user.isAnonymous)

removeOnUnmount could be used to remove the created script when the component calling useScript unmounts. Examples could be "one-shot" third party scripts that someone might just want to be present for a specific page of the app. Something like a HubSpot form that serves a specific use case, like Signing Up for an account.

If these sound like good ideas I'm happy to open a PR making the aforementioned changes.

@juliencrn
Copy link
Owner

Hi @curtvict,
Yeah, it's a cool idea, I'll be happy to review your PR.

What about a signature like this ?

interface UseScriptOptions {
  shouldLoad?: boolean
  removeOnUnmount?: boolean
}

useScript(src: string, options?: UseScriptOptions): Status { ... } 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants