Next.js Discord

Discord Forum

How to use PostHog with next.js, getting errors in provider

Answered
Chinese softshell turtle posted this in #help-forum
Open in Discord
Chinese softshell turtleOP
get this error

on this code

"use client"
import posthog from "posthog-js"
import { PostHogProvider } from "posthog-js/react"

if (typeof window !== "undefined") {
    posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY!, {
        api_host: process.env.NEXT_PUBLIC_POSTHOG_HOST
    })
}

export function PHProvider({ children }: { children: React.ReactNode }) {
    return <PostHogProvider client={posthog}>{children}</PostHogProvider>
}


I don't get why, it's from official docs of vercel

https://vercel.com/guides/posthog-nextjs-vercel-feature-flags-analytics
Answered by Chinese softshell turtle
ok I had to change it to .tsx
View full answer

1 Reply

Chinese softshell turtleOP
ok I had to change it to .tsx
Answer