React - How to pass props to a component passed as prop

前端 未结 2 2049
挽巷
挽巷 2021-02-11 13:44

I have a React component (React v15.5.4) that you can pass other components to:

class CustomForm extends React.Component {
  ...
  render() {
    return (
               


        
2条回答
  •  遇见更好的自我
    2021-02-11 14:34

    You have a couple of options to achieve what your asking.

    class SomeContainer extends React.Component {
      ...
      render() {
       let someObjectVariable = {someProperty: 'someValue'};
        return (
          }
           object={someObjectVariable}
          />
        );
      }
    

    }

    Or you can clone the component prop and apply the new props as Mayank said. In your case

    class CustomForm extends React.Component {
      ...
      render() {
        return (
          
    {React.cloneElement(this.props.component, {propFromParent:this.props.someObjectVariable})}
    ); } }

提交回复
热议问题