TypeError: items.Map不是函数



我的代码问题是,我想从后端创建一个令牌,并将其添加到我的项目。现在,由于映射数据,页面正在崩溃。

<div className='bg-gray-100'>
<SimpleHeader/>
<div className='flex justify-center'>
<h2 className='text-center text-4xl py-5 inline-block border-b-4 border-blue-400 font-bold mb-4'>My Items</h2>
</div>
<Link to='/addItems' className='flex justify-center'>
<button className='px-2 py-1 bg-transparent rounded border-2 border-blue-500 hover:bg-blue-500 hover:text-white duration-200 hover:scale-105'>Add New Item</button>
</Link>
<div className='container md:grid grid-cols-3 gap-4 w-full mx-auto p-12'>
{
items?.map(item=><MyItem key={item._id} item={item} handleDelete={handleDelete}></MyItem>)
}
</div>
</div>

试着这样修改

<div className='bg-gray-100'>
<SimpleHeader/>
<div className='flex justify-center'>
<h2 className='text-center text-4xl py-5 inline-block border-b-4 border-blue-400 font-bold mb-4'>My Items</h2>
</div>
<Link to='/addItems' className='flex justify-center'>
<button className='px-2 py-1 bg-transparent rounded border-2 border-blue-500 hover:bg-blue-500 hover:text-white duration-200 hover:scale-105'>Add New Item</button>
</Link>
<div className='container md:grid grid-cols-3 gap-4 w-full mx-auto p-12'>
{
items && items.map(item=><MyItem key={item._id} item={item} handleDelete={handleDelete}></MyItem>)
}
</div>
</div>

最新更新