0
我正在從我的React App向我的後端發出get請求。該調用是成功的,我能夠從後端接收值。但是,我無法將該值設置爲前端DOM。 這裏是我目前類的樣子:將一個道具的值從一個函數傳遞給React.JS中的render()
class App extends React.Component{
componentDidMount(){
this.props.getData();
}
renderProds(){
const data = this.props.products;
if(data){
data.map((e)=>{
return (
<Product
name={e.name}
desc={e.desc}
/>
);
});
}
}
render(){
return(
<div>{this.renderProds()}</div>
)
}
}
我確信,我的產品成分導入正確,它是接受道具name
和desc
。
我在做什麼錯?
這與我的退貨聲明有什麼不同? – Aditya
'data.map'方法創建一個新的數組,並在調用數組中的每個元素上調用提供的函數的結果。因此'data.map'中的返回狀態返回新數組的元素,而不是'renderProds'函數的返回值。 – huachengzan