Validation 如何在react js material ui中将数据从父组件传递到子组件并验证字段?

Validation 如何在react js material ui中将数据从父组件传递到子组件并验证字段?,validation,reactjs,material-ui,Validation,Reactjs,Material Ui,我目前正在react js中进行验证,并使用material ui进行验证。所以我有一个公共组件,我将拥有所有的验证逻辑。 我已经在我的公共组件中设置了获取所有字段值的状态,我需要在我的子组件中使用这些值,我想在子组件中单击按钮submit handleSubmit()验证每个字段。你能告诉我如何做到这一点吗。 在我的父组件下面: export default class CommonTextBox extends React.Component { constructor

我目前正在react js中进行验证,并使用material ui进行验证。所以我有一个公共组件,我将拥有所有的验证逻辑。 我已经在我的公共组件中设置了获取所有字段值的状态,我需要在我的子组件中使用这些值,我想在子组件中单击按钮submit handleSubmit()验证每个字段。你能告诉我如何做到这一点吗。 在我的父组件下面:

    export default class CommonTextBox extends React.Component {

      constructor(props) {
        super(props);

        this.state = {
          firstName:'',
          email:'',
          floatingLabel: '',
        };
        this.handleChange = this.handleChange.bind(this);
      }
      handleChange(evt) {
        if (this.props.name === 'a') {
          this.setState({ firstName: evt.target.value });
        } else if (this.props.name === 'b') {
          this.setState({ email: evt.target.value });
        }
      }
      render() {
        return (
          <div>
            <TextField maxLength='40' errorText='' floatingLabelText={this.state.floatingLabel} onChange={this.handleChange} />
          </div>
        );
      }
    }

Below my child component:

export default class PhysicianDetails extends React.Component {
  constructor(props) {
    // alert(1)
    super(props);
    this.state = {
    };
    this.handleSubmit = this.handleSubmit.bind(this);
  }
  handleSubmit() {
    }
  render() {
    return (
      <div>
        <CommonTextBox name='a' />
        <CommonTextBox name='b' />
        <RaisedButton label='Save' onClick={this.handleSubmit} />
      </div>
    );
  }
}
导出默认类CommonTextBox扩展React.Component{
建造师(道具){
超级(道具);
此.state={
名字:'',
电子邮件:“”,
浮动标签:“”,
};
this.handleChange=this.handleChange.bind(this);
}
手柄更换(evt){
如果(this.props.name=='a'){
this.setState({firstName:evt.target.value});
}else if(this.props.name=='b'){
this.setState({email:evt.target.value});
}
}
render(){
返回(
);
}
}
下面是我的孩子组件:
导出默认类PhysicianDetails扩展React.Component{
建造师(道具){
//警报(1)
超级(道具);
此.state={
};
this.handleSubmit=this.handleSubmit.bind(this);
}
handleSubmit(){
}
render(){
返回(
);
}
}

在父组件中编写验证函数。使用道具将函数传递给子组件。

在父组件中编写验证函数。使用道具将函数传递给孩子