[英]props.actions `undefined` when using redux and react.js
[英]props are not working when using map method in react.js
当我们将它们作为整个对象数组传递时,道具传递得很好,但是当我通过使用 map function 遍历数组来传递道具时,它不起作用。
import { React, useEffect, useState } from "react";
import axios from "axios";
import "./Home.css";
import Cardimg from "./Cardimg";
const Home = props => {
return (
<>
<div className="header">PHOTO GALLERY</div>
<div className="photos">
{props.data?.map(e => {
<Cardimg data={e.ImgUrl}></Cardimg>;
})}
</div>
</>
);
};
export default Home;
在上面的代码中,当我在 Cardimg 组件中手动传递时道具正在传递......但是一旦我开始使用 map 然后它就不起作用......就像道具没有到达组件一样。
下面是我的 Cardimg 组件
import React from 'react'
const Cardimg = (props) => {
console.log(props.data);
return (
<div>{props.data}</div>
)
}
export default Cardimg
需要在map
回调function里面返回Cardimg
组件。
要么像这样
{
props.data?.map(e => {
return <Cardimg data={e.ImgUrl}></Cardimg>;
});
}
或者像这样
{
props.data?.map(e => <Cardimg data={e.ImgUrl}></Cardimg>)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.