NextJS: "TypeError: Cannot read properties of null (reading 'useContext')"

Hello! I am currently trying to setup Piwik with a NextJS application, but it doesn’t seem to work.

I think the setup is done correctly, since I see my page views in the online analytics tool, and there isn’t much to be done wrong, but I’ll post it here as well:

<PiwikProProvider
    containerUrl="https://cyberjuice.containers.piwik.pro/"
    containerId="3e9feb18-3d3c-4221-83a5-066f8dd91bfd"
>
    <Component {...pageProps} />
</PiwikProProvider>

As soon as I try to use the usePiwikPro() hook, I get this error:

Anyone know why this happens?

I use React@17.0.2, and it seems that Piwik uses @18.2.0. Can this be the problem? I am not able to upgrade to React 18, because of other package dependencies.

It seems the solution was to import CustomEvent directly from @piwikpro/react-piwik-pro instead of using usePiwikPro.

@nbk we’ll try to confirm early next week. Sorry for a late response here, but one of our package maintainers is out of office this week.