Javascript 将组件推入阵列并传递道具的方法

Javascript 将组件推入阵列并传递道具的方法,javascript,reactjs,Javascript,Reactjs,将组件推送到阵列的这种方法是什么 days.push( <Day day={day} selected={selected} select={select}/> ); days.push( ); 我读了这段代码,但不理解其中的一些东西 class Week extends React.Component { render() { let days = []; let {date,} = th

将组件推送到阵列的这种方法是什么

days.push(

        <Day day={day}
          selected={selected}
          select={select}/>
      );
days.push(
);
我读了这段代码,但不理解其中的一些东西

class Week extends React.Component {
  render() {
    let days = [];
    let {date,} = this.props;
    const { month,selected,select, } = this.props;
    console.log(`Inside weeks ${month.toString()}`);
    console.log(`Selected weeks ${selected.toString()}`);


    for (var i = 0; i < 7; i++) {

      let day = {
          name: date.format("dd").substring(0, 1),
          number: date.date(),
          isCurrentMonth: date.month() === month.month(),
          isToday: date.isSame(new Date(), "day"),
          date: date
      };



      days.push(

        <Day day={day}
          selected={selected}
          select={select}/>
      );
      console.log(`days inside return is ${days.selected}`);
      date = date.clone();
      date.add(1, "day");
    }


    return (

      <div className="row week" key={days[0]}>
        {days}
      </div>
    );
  }

}
class-Week扩展了React.Component{
render(){
让天数=[];
设{date,}=this.props;
const{month,selected,select,}=this.props;
log(`Inside weeks${month.toString()}`);
log(`Selected weeks${Selected.toString()}`);
对于(变量i=0;i<7;i++){
让一天={
名称:日期格式(“dd”).子字符串(0,1),
编号:date.date(),
isCurrentMonth:date.month()==month.month(),
isToday:date.IsName(新日期(),“天”),
日期:日期
};
推(
);
log(`days inside return为${days.selected}`);
date=date.clone();
日期。添加(1,“天”);
}
返回(
{天}
);
}
}
我对代码中的这一步感到非常困惑,在这一步中,除了将属性传递给另一个类之外,它还被推送到一个数组中,然后返回相同的属性

<div className="row week" key={days[0]}>
        {days}
      </div>

{天}

这是一种在循环中动态渲染元素的方法。 渲染它们并将它们推送到数组中,然后渲染数组(由于数组是由react元素构建的,所以它只会渲染)。
看看这里:

道具不是被推到数组中,组件(React元素)是。你应该了解更多关于react@ReiDien你能解释一下上面的过程吗,或者把我链接到一些要阅读的东西上吗?首先,在react中,你可以显示一个变量<代码>{variable}。基本上,它只是创建一个React元素数组,然后进行渲染。那可不是什么花哨的东西。