我创建了三个基本组件。
A 呈现组件 B 和 C B 就像包含选项卡 1,2,3 的页眉 C 是第一页,其中有两个表单,一次显示一个。在显示第一个表单时,我需要在 B 组件中显示选项卡 1。在显示第二个表单时,我需要在 B 组件中显示选项卡 3。
我只想根据显示的表单将数据从 C 组件传递给 B 组件。
我将状态放在 C 组件上,并尝试使用相同的 this.state.data 或 this.props.data 来处理 B 控制器中没有值的情况。
jsx
import React from 'react';
import B from './B.jsx';
import C from './C.jsx'
class A extends React.Component {
    constructor(props) {
        super();
        this.state = {
            show : '1',
        }
    }
    render() {
        return (
            <div>{this.props.show}
                <B />
                <C/>
            </div>
        )
    }
}
export default A;
jsx
import React from 'react';
class B extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            show : '1',
        }
    }
    render() {
        return (
            //html code here
        )
    }
}
jsx
class C extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            show : '1',
        }
    }
    render() {
        return (
            //html code here
        )
    }
}