Reactjs 为什么子组件的道具比父组件多?

Reactjs 为什么子组件的道具比父组件多?,reactjs,redux,react-redux,Reactjs,Redux,React Redux,我有一个父组件,我想成为多个子组件的选项卡。由于某些原因,我的子组件比父组件拥有更多的道具数据 父组件 import React, { Component} from 'react'; import { Link } from 'react-router'; import { connect } from 'react-redux'; class TerritoryTabs extends Component { componentWillMount() { console.lo

我有一个父组件,我想成为多个子组件的选项卡。由于某些原因,我的子组件比父组件拥有更多的道具数据

父组件

import React, { Component} from 'react';
import { Link } from 'react-router';
import { connect } from 'react-redux';

class TerritoryTabs extends Component {

  componentWillMount() {
    console.log('this is the parent props (tabs)')
    console.log(this.props);
  }

  render() {
    return (

    {this.props.children}

    );
  }

}

export default connect(null, null)(TerritoryTabs);
子组件

import React, { Component} from 'react';
import { Link } from 'react-router';
import { connect } from 'react-redux';
import { reduxForm } from 'redux-form';

import { getTerritoryGeographies } from '../actions/index';

import TerritoryTabs from './territory-tabs';

class TerritoryGeographyList extends Component {

  componentWillMount() {
    console.log('this is child props (TerritoryGeographyList)');
    console.log(this.props);
    this.props.getTerritoryGeographies(this.props.params.id);
  }

  render() {
    return (
    <TerritoryTabs>

          <div>This list goes here</div>

    </TerritoryTabs>
    );
  }
}

function mapStateToProps(state) {
  return { territoryGeographies: state.territoryGeographies.all
        };
}

export default connect(mapStateToProps, { getTerritoryGeographies })(TerritoryGeographyList);
import React,{Component}来自'React';
从“反应路由器”导入{Link};
从'react redux'导入{connect};
从'redux form'导入{reduxForm};
从“../actions/index”导入{getTerritoryGeographies};
从“./territory tabs”导入TerritoryTabs;
类TerritoryGeographyList扩展组件{
组件willmount(){
log(“这是子道具(TerritoryGeographyList)”;
console.log(this.props);
this.props.getTerritoryGeographies(this.props.params.id);
}
render(){
返回(
这个清单在这里
);
}
}
函数MapStateTops(状态){
返回{territoryGeographies:state.territoryGeographies.all
};
}
导出默认连接(mapStateToProps,{getTerritoryGeographies})(TerritoryGeographyList);
这是控制台打印的内容


包裹组件应称为“父级”。例如:

<Parent>
    <Child />
</Parent>

因此,在您的情况下,修复这一行:

class TerritoryTabs extends Component {

  componentWillMount() {
    console.log('this is the child props (tabs)') // <-- Fix this line, it should be the "child"
    console.log(this.props);
  }
class TerritoryGeographyList extends Component {

  componentWillMount() {
    console.log('this is parent props (TerritoryGeographyList)'); // <-- fix this line, it should be "parent"
    console.log(this.props);
    this.props.getTerritoryGeographies(this.props.params.id);
  }
类TerritoryTabs扩展组件{
组件willmount(){

log('这是子道具(选项卡)//我不确定你在问什么,而且你没有显示实际的JSX(或其他什么)这说明了这一点。如果你给它传递更多的道具,它就会有更多的道具,再加上你映射了一个道具。@DaveNewton但我的孩子有更多的道具数据。所以我需要把道具从孩子传递给父母?这不违反react约定吗?你的“孩子”组件(TerritoryGeographyList)正在包装你的“父母”组件(TerritoryTabs).有意思,你为什么这么叫他们?包裹的应该叫“家长”是的,TerritoryGeographyList是父对象。
TerritoryGeographyList是子对象。
TerritoryTabs是子对象。你只是有点混淆。不是。
TerritoryGeographyList是父对象,它呈现它的子对象。
TerritoryGeographyList
@TylerZika:记住一点:父对象是在其呈现方法中呈现子对象的对象。因此父级可以通过在渲染时向子级添加属性向子级传递道具(例如