I've got some data that multiple pages within my app use. Since the fetch time is atrocious, I'd like to fetch that data when someone loads the site, and then pass that data off to multiple different pages to render in different ways.
My understanding from this question is that you aren't able to use getServerSideProps within the _app.tsx
. What is the standard for propagating props across your app for NextJS? My guess was to useEffect
in the _app.tsx
, but that has led to many issues where the data isn't initialized and never updates.
some napkin-code for context
// _app.tsx
function CustomApp({ Component, pageProps }: AppProps) {
const [data, setData] = useState<DataPoint[]>([])
useEffect(() => {
getMyData.then(data => setData(data))
}, [])
return (
<Component {...pageProps} initialData={data}/>
)
}
// index.tsx
export function Index({initialData}) {
const [data, setData] = useState(initialData)
return (
<Graph {...data} />
)
}
// anotherPage/index.tsx
export function AnotherPage({initialData}) {
const [data, setData] = useState(initialData)
return (
<Table {...data}>
)
}