简体   繁体   English

nextjs 中 getServerSideProps 中的 next-redux-wrapper

[英]next-redux-wrapper in getServerSideProps in nextjs

I am trying to call one action function in getServerSideProps.我正在尝试在 getServerSideProps 中调用一个操作 function。 I am using typeScript.我正在使用 typeScript。

Actually, in javascript I use it only this way-实际上,在 javascript 中我只这样使用它-

import { wrapper } from "Redux/store";
import { getVideo } from "Redux/Actions/videoAction";
//Serversider data fatching
export const getServerSideProps = wrapper.getServerSideProps(
  (store) =>
    async (context) => {
      await store.dispatch(getVideo());
    }
)

But When I am trying to use it in typescript I faced some problems.但是当我尝试在 typescript 中使用它时,我遇到了一些问题。 I can solve some but One is not understanding.我可以解决一些,但一个不理解。

export const getServerSideProps = wrapper.getServerSideProps(
  (store) =>
    async (context) => {
      await store.dispatch(getNews() as any);
    }
)

Here I use getNews() as any types.在这里,我将getNews() as any类型。 I can't say it is right or wrong!我不能说这是对还是错!

My main problem is context and async function-我的主要问题是上下文和异步函数-

I actually finding this error-我实际上发现了这个错误- 在此处输入图像描述

Error clearly explains it: You have to return Promise<GetServerSidePropsResult<any>>错误清楚地解释了它:You have to return Promise<GetServerSidePropsResult<any>>

In your current function you are not returning anything.在您当前的 function 中,您没有返回任何东西。 if you annotate getSerververSideProps:如果你注释 getSerververSideProps:

import { GetServerSideProps } from "next";

export const getServerSideProps: GetServerSideProps =
  wrapper.getServerSideProps(async (context) => {}

if you hover over GetServerSideProps , its type definition如果你 hover 通过GetServerSideProps ,它的类型定义

(alias) type GetServerSideProps<P extends { [key: string]: any; } = { 
  [key: string]: any; }, Q extends ParsedUrlQuery = ParsedUrlQuery> =
  (context: GetServerSidePropsContext<Q>) Promise<GetServerSidePropsResult<P>>

Just add return statement只需添加返回语句

return { props: { id: null } };

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 typescript、next-redux-wrapper、getServerSideProps? - how to use typescript, next-redux-wrapper, getServerSideProps? Next.js:getServerSideProps 无法使用 Next.js 和 Next-redux-wrapper 以及 TypeScript - Next.js: getServerSideProps not working using Next.js with Next-redux-wrapper with TypeScript Next.js:使用带有 TypeScript 的 next-redux-wrapper 在 getServerSideProps 中调用 Thunks? - Next.js: Calling Thunks in getServerSideProps with next-redux-wrapper with TypeScript? 如何正确使用带有“Next.js”、“Redux-ToolKit”和 Typescript 的“next-redux-wrapper”? - How to use "next-redux-wrapper" with "Next.js", "Redux-ToolKit" and Typescript properly? Redux 工具包 typescript 类型问题与 next js 和 next-redux-wrapper - Redux toolkit typescript type issue with next js and next-redux-wrapper 使用 redux-persist 和 next-redux-wrapper (Typescript) 不更新存储 - storage is not being update using redux-persist with next-redux-wrapper (Typescript) next-redux-wrapper 通用类型“MakeStore”在 configureStore 中需要 1 个类型参数 - next-redux-wrapper Generic type 'MakeStore' requires 1 type argument(s) in configureStore Next.js GetServerSideProps 自定义包装器 TypeScript - Next.js GetServerSideProps custom wrapper TypeScript Redux Toolkit 和 typescript 中的 Next Redux Wrapper 类型错误? - Type error with Redux Toolkit and Next Redux Wrapper in typescript? 您正在使用旧版实现。 请更新您的代码:使用 createWrapper() 和 wrapper.useWrappedStore()。 nextjs redux? - You are using legacy implementaion. Please update your code: use createWrapper() and wrapper.useWrappedStore(). nextjs redux?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM