Currently, I am utilizing RTK Query to make an API call within my getServerSideProps
function. While I can successfully retrieve the result using the code snippet provided below, I find the process somewhat awkward. Additionally, the result lacks proper typing, which is suboptimal.
export const getServerSideProps: GetServerSideProps = wrapper.getServerSideProps(
(store) => async (context: GetServerSidePropsContext) => {
await store.dispatch(apiCall.initiate({ ...someParams }))
await Promise.all(api.util.getRunningOperationPromises())
const mutations = store.getState().api.mutations;
const mutation = Object.values(mutations).find((m) => m?.endpointName === 'apiCall')
// |________| -> type is `unknown`
if (mutation?.error) {
const error = mutation.error as {
status: number
data: {
error: string
}
}
}
return {
props: {},
}
},
)
I'm seeking a more efficient approach for handling this situation. Any suggestions?