将Google Analytics添加到带有下一个redux包装的Nextjs应用程序中



我创建了一个带有redux包装的nextjs应用程序

class MyApp extends React.Component<AppProps> {

public static getInitialProps = wrapper.getInitialAppProps(store => async ({ Component, ctx }) => {

我现在正在尝试将谷歌分析集成到应用程序中(G4(。尽管许多文档解释了如何使用useEffect添加,但在应用程序扩展组件而不使用钩子的情况下,指南中关于如何使用它们的内容几乎没有中断。

我是否需要使用componentMount方法,或者有更好的方法,比如将此实现升级为功能组件?

将应用程序转换为功能组件并使用useEffect

const MyApp = (AppProps) => {
const router = useRouter();
useEffect(() => {

然后

MyApp.getInitialProps = wrapper.getInitialAppProps(store => async ({ Component, ctx }) => {

相关内容

最新更新