When trying to call an action function in getServerSideProps using TypeScript, I encountered some challenges. In JavaScript, it is straightforward:
import { wrapper } from "Redux/store";
import { getVideo } from "Redux/Actions/videoAction";
//Serverside data fetching
export const getServerSideProps = wrapper.getServerSideProps(
(store) =>
async (context) => {
await store.dispatch(getVideo());
}
)
However, when attempting the same in TypeScript, issues arose.
export const getServerSideProps = wrapper.getServerSideProps(
(store) =>
async (context) => {
await store.dispatch(getNews() as any);
}
)
I used getNews() as any
here, but I'm unsure if it's the correct approach.
The main challenge lies with context and async functions. This led to a specific error that I'm struggling to resolve.
This is the error I'm encountering: https://i.stack.imgur.com/yDPLr.png