2017-01-19 3 views
0

親から来たが小道具が1つ変更された小道具はどうやって送るのですか?子供に送るthis.props with one props

私はレンダリングしているページがあります。InputListコンポーネント。そして、このコンポーネントでは、InputListを再度レンダリングしています。だから、私は{...this.props}を1つの小道具交換で送る。modal。しかし、私が<InputList modal={true} {this.props}/>を送るとき。 modalの値は...this.propsからです。値はtrueの代わりにfalseとなります。

確かに、すべての小道具を個別に送る可能性がありますが、小道具がたくさんあるので、私はthis.propsを使用します。または、私はconst { modal, ...others} = this.propsのようなものを使用できますが、私はconst { modal,...,...,...,...,...} = this.props

class Page extends Component{ 
     render(){ 
     return(
       <InputList modal={false} list={...} valueA={..} valueB={..} 
        firstTitle={..} secondTitle={..} /> 
     ) 
     } 
    } 

    class InputList extends Component{ 
     render(){ 
      const {modal,list,valueA,valueB,firstTitle,secondTitle} = this.props; 
      .... 
     return(
      .... 
       <InputList modal={true} {...this.props} /> 
     ) 
     } 
    } 

答えて

1

これはあなたのために働くでしょうか?

class InputList extends Component { 
    render(){ 
    const passProps = Object.assign({}, this.props, {modal: true}) 
    return(
     .... 
     <InputList {...passProps} /> 
    ) 
} 
+0

ありがとうございますが、これは唯一の解決策ですか? –