代码之家  ›  专栏  ›  技术社区  ›  Nikul Panchal

获取错误:void不可分配给react js中的“FC<IPickWinnerProps>”类型

  •  0
  • Nikul Panchal  · 技术社区  · 4 年前

    当我运行我的站点时,我在react js中得到了这个错误

    TypeScript error in /var/www/oxygen/allbadcards/client/src/Areas/Game/GamePlayBlack.tsx(29,14):
    Type '({ onPickWinner, canPick, timeToPick, hasWinner, revealMode }: PropsWithChildren<IPickWinnerProps>) => void' is not assignable to type 'FC<IPickWinnerProps>'.
      Type 'void' is not assignable to type 'ReactElement<any, string | ((props: any) => ReactElement<any, string | ... | (new (props: any) => Component<any, any, any>)> | null) | (new (props: any) => Component<any, any, any>)> | null'.  TS2322
    

    在这里我已经上传了我的全部代码,谁能帮我为什么我得到这个错误?

    export interface IPickWinnerProps
    {
        children?: undefined;
        canPick: boolean;
        timeToPick: boolean;
        revealMode: boolean;
        hasWinner: boolean;
    }
    
    export const PickWinnerIdle: React.FC<IPickWinnerProps> = (
        {
            onPickWinner,
            canPick,
            timeToPick,
            hasWinner,
            revealMode
        }
    ) =>
    {
        const gameData = useDataStore(GameDataStore);
        const userData = useDataStore(UserDataStore);
        const [pickWinnerLoading, setPickWinnerLoading] = useState(false);
        setPickWinnerLoading(true);
    }
    
    1 回复  |  直到 4 年前
        1
  •  0
  •   felixmosh    4 年前

    你忘了从 PickWinnerIdle 因此,函数组件返回“void”。

    export const PickWinnerIdle: React.FC<IPickWinnerProps> = ({
      onPickWinner,
      canPick,
      timeToPick,
      hasWinner,
      revealMode,
    }) => {
      const gameData = useDataStore(GameDataStore);
      const userData = useDataStore(UserDataStore);
      const [pickWinnerLoading, setPickWinnerLoading] = useState(false);
      setPickWinnerLoading(true);
      return <div>bla</div>; // <---
    };