反应:TypeError:Object(...) 不是函数

问题描述

通过继续我研究 react js 的项目,我遇到了一个错误

TypeError: Object(...) 不是函数

我到处找,但找不到解决错误方法 这是我的 PokemonsContainer.js 文件

import React from "react";
import useQuery from "@apollo/react-hooks";
import {GET_POKEMONS}  from "../graphql/get-pokemons";
import { Pokemon } from "../components/Pokemon";


 function PokemonsContainer() {
    const { data: { pokemons = [] } = {} } = useQuery(GET_POKEMONS,{ variables: { first: 9 },});
    
    return (
        <div className="container">
            {pokemons && pokemons.map(pokemon => <Pokemon key={pokemon.id} pokemon={pokemon} />)}
        </div>
    );
}
export default PokemonsContainer

错误显示在第 8 行 const { data: { pokemons = [] } = {} } = useQuery(GET_POKEMONS,});

这是查询文件 get-pokemons.js

import gql from 'graphql-tag'

export const GET_POKEMONS =gql`
    query pokemons($first: Int!){
        pokemons(first:$first){
            id
            name
            image
            maxHP
            maxCP
            attacks{
                special{
                    name
                    damage
                }
            }
        }
    }
`;

这里是 Pokemon.js

import React from 'react';

export function Pokemon({ pokemon }) {
    return (<p>{pokemon.name}</p>)
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)