Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion nextjs-ssr/checkout/async-pages/checkout.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const Checkout = props => (
`}</style>
</div>
);
Checkout.getInitialProps = async () => {
export const getServerSideProps = async () => {
const swapi = await fetch('https://jsonplaceholder.typicode.com/todos/1').then(res => res.json());
console.log(swapi);
console.log('swapi');
Expand Down
8 changes: 4 additions & 4 deletions nextjs-ssr/checkout/pages/checkout.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import dynamic from 'next/dynamic';
const page = import('../async-pages/checkout');

const Page = dynamic(() => import('../async-pages/checkout'));
Page.getInitialProps = async ctx => {
const getInitialProps = (await page).default?.getInitialProps;
if (getInitialProps) {
return getInitialProps(ctx);
export const getServerSideProps = async ctx => {
const getServerSideProps = (await page).getServerSideProps
if (getServerSideProps) {
return getServerSideProps(ctx);
}
return {};
};
Expand Down
9 changes: 5 additions & 4 deletions nextjs-ssr/home/pages/checkout.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import dynamic from 'next/dynamic';

const Page = dynamic(() => import('checkout/checkout'));
Page.getInitialProps = async ctx => {

export const getServerSideProps = async ctx => {
const page = import('checkout/checkout');
const getInitialProps = (await page).default?.getInitialProps;
if (getInitialProps) {
return getInitialProps(ctx);
const getServerSideProps = (await page).getServerSideProps;
if (getServerSideProps) {
return getServerSideProps(ctx);
}
return {};
};
Expand Down