PostHog / posthog-js-lite

Reimplementation of posthog-js to be as light and modular as possible.
https://posthog.com/docs/libraries
MIT License
70 stars 36 forks source link

fix: undefined posthog in hooks #184

Closed marandaneto closed 9 months ago

marandaneto commented 9 months ago

Problem

Probably solves https://github.com/PostHog/posthog-js-lite/issues/182

I suspect that when there are more promises to be resolved, posthog tries to use its instance but it's not ready yet.

Changes

The changes allow passing the custom posthog to the hooks instead of always using usePostHog, which is likely already resolved since it was either passed or created by the provider. If it's not ready, at least it'll bail out instead of crashing.

Release info Sub-libraries affected

Bump level

Libraries affected

Changelog notes

github-actions[bot] commented 9 months ago

Size Change: 0 B 🆕

Total Size: 0 B

compressed-size-action

marandaneto commented 9 months ago

Change looks good to me. Not really clear what I would change in my code as an integrator to fix the crash (if anything). Might be worth documenting that or making an example if you think it's necessary

there's no change to be made since the client is optional and the provider creates them automatically, the provider already has an optional client which is already passed.