use*_*396 5 next.js getserversideprops
下面这句话大家都很熟悉:You should not use getInitialProps, but getServerSideProps instead. 我已经使用构建了我的应用程序getInitialProps,现在我面临以下问题:“我是否应该将 getInitialProps 替换为 getServerSideProps?”,如果是这样,我应该如何以正确的方式进行操作而不损坏我的应用程序?
今天,我getInitialProps在几个重要的地方使用:
_app.js中react-redux:class MyApp extends App {
static async getInitialProps({ Component, ctx }) {
return {
pageProps: {
...(Component.getInitialProps
? await Component.getInitialProps(ctx)
: {})
}
};
}
render() {
const { Component, pageProps, store } = this.props;
return (
<>
<Provider store={store}>
<Component {...pageProps} />
</Provider>
</>
);
}
}
export default withRedux(initStore)(withReduxSaga(MyApp));
Run Code Online (Sandbox Code Playgroud)
如何用 getServerSideProps 替换 getInitialProps?
任何建议将不胜感激,谢谢
| 归档时间: |
|
| 查看次数: |
594 次 |
| 最近记录: |