posthog-js icon indicating copy to clipboard operation
posthog-js copied to clipboard

Clarify the reason for always using the React provided client

Open joshua-clarify opened this issue 2 months ago • 1 comments

Is your feature request related to a problem?

In the PostHog React docs, it mentions you must use the PostHog provided client

Image

However, looking at PostHogProvider and usePostHog, all it does is return the global initialized client.

Use case: we would like to be able to track events in and outside of React.

Describe the solution you'd like

Please clarify in the docs whether it is safe to just import the global client if we handle initialization.

Describe alternatives you've considered

Why is a hook even necessary?

Related sub-libraries

  • [ ] All of them
  • [x] posthog-js (web)
  • [ ] posthog-js-lite (web lite)
  • [ ] posthog-node
  • [ ] posthog-react-native
  • [x] @posthog/react
  • [ ] @posthog/ai
  • [ ] @posthog/nextjs-config

Additional context

Thank you for your feature request – we love each and every one!

joshua-clarify avatar Oct 22 '25 16:10 joshua-clarify

I'm also curious about this.

It would very convenient to know I can safely call posthog methods outside the React context.

samzmann avatar Nov 13 '25 10:11 samzmann