This is the code to my App Container
import { useEffect } from "react"
import axios from 'axios'
import { useSelector, useDispatch } from "react-redux"
import { setUserState } from '../slices/userSlice'
import {delay} from '../util/delay'
export default function AppContainer({pageProps, Component, data}) {
const user = useSelector((state) => state.user.value)
return (
<>
{console.log(data)}
<Component {...pageProps} />
</>
)
}
export async function getServerSideProps(context) {
console.log("Hello")
return {
props: {
data: "Hello"
}
}
}
App Container is in _app.js, so the component is being rendered every single time. However, getServerSideProps does not appear to be running. It does not console.log anything in both client and server, and when I console.log {data}, it says undefined, although getServerSideProps returns it as "Hello".
CodePudding user response:
_app.js does not support Next.js Data Fetching methods like getStaticProps or getServerSideProps. You must use the data fetching method inside your page apart from _app.js.