Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 未处理的拒绝(TypeError):props.products.map不是函数_Reactjs_Dictionary_Render - Fatal编程技术网

Reactjs 未处理的拒绝(TypeError):props.products.map不是函数

Reactjs 未处理的拒绝(TypeError):props.products.map不是函数,reactjs,dictionary,render,Reactjs,Dictionary,Render,我正在处理react,我遇到了这个错误。我觉得好像没有什么错误,但是代码不起作用。我希望任何人都能帮上忙。下面是更新的代码:代码用于cartPage,但cartPage正在运行。当我单击购物车图标(仅包含商品)时,会弹出此错误 import React from 'react' function UserCardBlock(props) { const renderCartImage = (images) => { if(images.length >

我正在处理react,我遇到了这个错误。我觉得好像没有什么错误,但是代码不起作用。我希望任何人都能帮上忙。下面是更新的代码:代码用于cartPage,但cartPage正在运行。当我单击购物车图标(仅包含商品)时,会弹出此错误

  import React from 'react'

function UserCardBlock(props) {

    const renderCartImage = (images) => {
        if(images.length > 0) {
            let image = images[0]
            return `http://localhost:5000/${image}`
        }
    }

    const renderItems = () => (
        props.products && props.products.map(product => (
            <tr key={product._id}>
                <td>
                    <img style={{ width: '70px' }} alt="product" 
                    src={renderCartImage(product.images)} />
                </td> 
                <td>{product.quantity} EA</td>
                <td>$ {product.price} </td>
                <td><button 
                onClick={()=> props.removeItem(product._id)}
                >Remove </button> </td>
            </tr>
        ))
    )

    return (
        <div>
            <table>
                <thead>
                    <tr>
                        <th>Product Image</th>
                        <th>Product Quantity</th>
                        <th>Product Price</th>
                        <th>Remove from Cart</th>
                    </tr>
                </thead>
                <tbody>
                    {renderItems()}
                </tbody>
            </table>
        </div>
    )
}

export default UserCardBlock
从“React”导入React
功能用户卡块(道具){
const renderCartImage=(图像)=>{
如果(images.length>0){
让图像=图像[0]
返回`http://localhost:5000/${image}`
}
}
常量renderItems=()=>(
props.products&&props.products.map(产品=>(
{product.quantity}EA
${product.price}
props.removietem(product.\u id)}
>除去
))
)
返回(
产品形象
产品数量
产品价格
从购物车上取下
{renderItems()}
)
}
导出默认UserCardBlock

存在props.products,但它不是数组。尝试
console.log(道具产品)
查看值或发布其余代码。

道具。产品
不是数组。
我认为您应该尝试
Array.isArray(props.products)&&&……

显然,props.products不是数组。你能告诉我们你在道具上经过哪里吗?