简体   繁体   English

不可分配给 [React] 类型的参数

[英]is not assignable to parameter of type [React]

I have problem in react I wrote enum type我在反应中遇到问题我写了枚举类型

enum.ts枚举

export enum DivingType {
  FreeDiving = "FreeDiving",
  ScubaDiving = "ScubaDiving",
}

and my home screen has graphql hooks我的主屏幕有 graphql 钩子

home.tsx主页.tsx

import { DivingType } from "..."

export const Home = () => {
  const [divingType, setDivingType] = useState<DivingType>(DivingType.FreeDiving)
  const [pageNumber, setPageNumber] = useState(1)

  useMatchingList(divingType, pageNumber)
  
  // --------------------[ Return ]--------------------
  return ...

useMatchingList.tsx useMatchingList.tsx

interface IUseMatchingListProps {
  divingType: DivingType
  pageNumber: number
}
export const useMatchingList: React.FC<IUseMatchingListProps> = ({
  divingType,
 ,
}) => {...}

and I have我有

Argument of type 'import("...").DivingType' is not assignable to parameter of type 'PropsWithChildren<IUseMatchingListProps>'

useMatchingList(divingType, pageNumber)
       |            ^

what is the matter ?有什么事 ? please help me !请帮我 !

The FC in React.FC means "Functional Component". React.FCFCReact.FC是“功能组件”。 And a hook is not a component.一个钩子不是一个组件。 A custom hook is just a function that calls other hooks.自定义钩子只是调用其他钩子的函数。 So it takes arguments just like any function would.所以它就像任何函数一样需要参数。

That means your hooks should look more like this:这意味着你的钩子应该看起来更像这样:

export const useMatchingList = (divingType: DivingType, pageNumber: number) => {
  // my hook implementation
}

Working typesafe example 工作类型安全示例

暂无
暂无

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

相关问题 React Typescript不可分配给type参数 - React typescript is not assignable to parameter of type 类型参数不可分配给“SetStateAction”类型的参数<never[]> &#39;。 在反应中 - Argument of type is not assignable to parameter of type 'SetStateAction<never[]>'. in React React 组件上的 Typescript 错误:“元素”类型的参数不可分配给类型的参数 - Typescript error on React Component: Argument of type 'Element' is not assignable to parameter of type React Typescript:'{ [x: number]: any; 类型的参数 }' 不可分配给类型的参数 - React Typescript: Argument of type '{ [x: number]: any; }' is not assignable to parameter of type 参数类型不能分配给类型的参数 - Argument type is not assignable to parameter of type [type]类型的参数不能分配给[type]类型的参数 - Argument of type [type] is not assignable to parameter of type [type] 无法将unhandledRejection分配给Signals类型的参数 - unhandledRejection is not assignable to parameter of type Signals 具有Typescript和react-redux的状态组件:类型&#39;typeof MyClass&#39;的参数不能分配给类型Component的参数 - Stateful Component with Typescript and react-redux: Argument of type 'typeof MyClass' is not assignable to parameter of type Component 如何修复'Date []'类型的参数不能分配给反应中'(prevState:undefined)类型的参数 - How to fix the Argument of type 'Date[]' is not assignable to parameter of type '(prevState: undefined) in react '(props: ITableProps) =&gt; JSX.Element' 类型的参数不能分配给类型的参数...... - React HOC - Argument of type '(props: ITableProps) => JSX.Element' is not assignable to parameter of type … - React HOC
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM