NodeJS 未捕获的类型错误:guilds.map不是函数

f5emj3cl  于 2023-08-04  发布在  Node.js
关注(0)|答案(1)|浏览(89)

我对discord.js编码很陌生,并且自己也为我的discord.js bot创建了一个 Jmeter 板,但我遇到了这个问题,我不知道如何解决它,有人能帮助我吗?如果你想要一些其他的文件,我会添加它们!错误代码:

MenuWrapper index.jsx

import React from 'react';
    import { Link } from "react-router-dom";
    
    
    
    export function MenuComponent( {
      guilds,
    }) {
        
        
    
        return (
            <div>
              {
                guilds.map((guild) => (
                    <div>
                       <li>{ guild.name }</li>
                       <Link to= { `/dashboard/${guild.id}` }>View Dashboard</Link>
                    </div>
                ))
              }
            </div>
        );
    }

字符串

MenuComponent使用方法:

import React from 'react';
import { getGuilds, getUserDetails } from '../../utils/api';
import { useNavigate } from 'react-router-dom';
import { useEffect } from 'react';
import { MenuComponent } from '../../components';
import background from "./placeholder.png";

export function MenuPage( {

}) {
    
    const [user, setUser] = React.useState(null);
    const [loading, setLoading] = React.useState(true);
    const [guilds, setGuilds] = React.useState( [] );
    let history = useNavigate();
    useEffect(() => {
        getUserDetails()
        .then(({ data }) => {
          console.log(data);
          setUser(data);
          setGuilds(data);
          
          setLoading(false);
          return getGuilds();
        }).then(({data}) => {

          console.log(data);
          setGuilds(data);
          

        }).catch((err) => {
            setLoading(false);
        });
    }, [])

    return !loading && (
        <div>
          <h1>Menu Page</h1>
          <MenuComponent guilds={ guilds }/>
          
        </div>
    )
}


我真的很感激任何帮助,因为我一直在试图解决这个问题几个小时!

nuypyhwy

nuypyhwy1#

import React from 'react';
    import { Link } from "react-router-dom";
    
    
    
    export function MenuComponent( {
      guilds,
    }) {
        
        
    
        return (
            <div>
              {
                guilds && guilds.map((guild) => (
                    <div>
                       <li>{ guild.name }</li>
                       <Link to= { `/dashboard/${guild.id}` }>View Dashboard</Link>
                    </div>
                ))
              }
            </div>
        );
    }

字符串
你能试试这个吗

相关问题