I get the data when I use useEffect
instead of getStaticProps
. But in getStaticProps
it's showing that hooks can only be use in functional component.
import Head from 'next/head'
import Image from 'next/image'
import Sidebar from '../components/Sidebar'
import styles from "../styles/Home.module.css"
import CssBaseline from '@mui/material/CssBaseline'
import Navbar from '../components/Navbar'
import Mainbody from '../components/Mainbodi'
import { useGetCryptosQuery } from '../services/CryptoApi'
export default function Homee({res}) {
console.log(res);
return (
<div>
<div className={styles.container}>
<CssBaseline />
<Sidebar/>
<div className={styles.bodi}>
<Navbar/>
<Mainbody/>
</div>
</div>
</div>
)
}
export const getStaticProps = async() => {
const {data, isFetching} = await useGetCryptosQuery()
return {
props: {
res: data.data.coins
}
}
}
With the release of RTK query version 1.7, support for SSR is available. Although, according to the official docs, you need to setup next-redux-wrapper first.
At the moment, using RTK Query with Next is only possible in non-SSR-Scenarios. That will change with RTK version 1.7.
See https://github.com/reduxjs/redux-toolkit/pull/1277
You can use the rest of RTK as you want with Next.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With