NextJS - 如何组合多个 getServerSideProps 包装器?

问题描述

我在 NextJs 应用中使用了两个库:next-firebase-authnext-redux-wrapper。它们都要求我用它们各自的函数包装 getServerSideProps

对于next-firebase-auth

export const getServerSideProps = withAuthUseRSSR()(async ({ AuthUser }) => {
    // Some code
})

对于next-redux-wrapper

export const getServerSideProps = wrapper.getServerSideProps(
    ({store}) => {
        // Some code
    }
);

两者都单独工作,但我无法让两者同时工作。 NextJs 只允许 getServerSideProps 声明一次。是否有可能以某种方式组合多个包装器?

解决方法

您可以一个接一个地链接包装器。内部函数将包含两者传递的额外道具。

export const getServerSideProps = withAuthUserSSR()(wrapper.getServerSideProps(
    ({ AuthUser,store,res,req }) => {
        // Some code
    }
))

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...