Reactjs 我是否可以映射两个数组,使它们都渲染到同一个卡组件?
我将两个数组上的状态传递给列表组件 用户数组和tweets数组Reactjs 我是否可以映射两个数组,使它们都渲染到同一个卡组件?,reactjs,jsx,Reactjs,Jsx,我将两个数组上的状态传递给列表组件 用户数组和tweets数组 {this.props.tweets.map(el,i=>{ 返回( ) })} 有没有一种方法能够同时传递这两种状态并映射到具有两种不同映射函数且必须分别传递状态的vs 是的,您可以在将这两个数组映射到卡组件之前将其合并 假设另一个数组名为otherTweets,则应将第一行替换为: {[…this.props.tweets,…this.props.otherTweets].map(el,i=>{ 在这里,我们使用扩展运算符将
{this.props.tweets.map(el,i=>{
返回(
)
})}
有没有一种方法能够同时传递这两种状态并映射到具有两种不同映射函数且必须分别传递状态的vs
是的,您可以在将这两个数组映射到
卡
组件之前将其合并
假设另一个数组名为otherTweets
,则应将第一行替换为:
{[…this.props.tweets,…this.props.otherTweets].map(el,i=>{
在这里,我们使用扩展运算符将两个不同的数组合并为一个您是想将两个相同类型的数组合并,还是想让两个数组并行迭代,因为数据在两个数组中被分割?
{this.props.tweets.map(el, i => {
return (
<div className="tweetCard">
<Card
name={users[i].name}
username={users[i].username}
pic={users[i].profile_image_url}
following={users[i].public_metrics.following_count}
followers={users[i].public_metrics.followers_count}
userTweet={users[i].public_metrics.tweet_count}
tweet={el.text}
date={el.created_at}
likes={el.public_metrics.like_count}
retweets={el.public_metrics.retweet_count}
replies={el.public_metrics.reply_count}
/>
</div>
)
})}