“使用客户端”入口文件中的组件Props必须可序列化,“setShow”无效.ts(71007)

问题描述 投票:0回答:1

对于 React 中的一些 prop 命名,我在 VS Code 编辑器中收到此 Typescript 警告/错误。

Props must be serializable for components in the "use client" entry file, "setShow" is invalid.ts(71007)

例如:

const ComponentName = ({ show, setShow }: IComponentName) => {
...
Component logic    
...
}

其中,

setShow
是更新状态的函数,从
parent
传递到
child

但是项目构建成功了。

为什么TS会对道具上的某些命名发出警告?名称

setShow
作为道具名称有什么问题?如何让 TS 不针对这些命名抛出警告/错误?

reactjs typescript next.js react-props
1个回答
0
投票

这对我有用,用普通函数替换箭头函数

❌代替:

type Props = {
  onFinish: (status: string) => void; 
};

✅ 使用这个:

type Props = {
  onFinish(status: string): void; 
};
© www.soinside.com 2019 - 2024. All rights reserved.