Javascript Reactjs-将相同的道具传递给多个子组件
我有一个父组件,它有几个子组件。为子组件传递的道具都是相同的。比如说Javascript Reactjs-将相同的道具传递给多个子组件,javascript,reactjs,Javascript,Reactjs,我有一个父组件,它有几个子组件。为子组件传递的道具都是相同的。比如说 <TextQuestion questionInfo={this.props.questionInfo} key={this.props.questionInfo.module_question_id} handleChange={this.handleChange} /> <DropDown questionInfo={this.props.questionInfo} key={this.props.qu
<TextQuestion questionInfo={this.props.questionInfo} key={this.props.questionInfo.module_question_id} handleChange={this.handleChange} />
<DropDown questionInfo={this.props.questionInfo} key={this.props.questionInfo.module_question_id} handleChange={this.handleChange} />
<Checkbox questionInfo={this.props.questionInfo} key={this.props.questionInfo.module_question_id} handleChange={this.handleChange} />
有没有更有效的方法?可能是一个函数调用,返回道具并添加到子组件
const someProps = {
questionInfo: this.props.questionInfo,
key: this.props.questionInfo.module_question_id,
handleChange: this.handleChange,
}
<TextQuestion {...someProps} />
<DropDown {...someProps} />
{[TextQuestion, DropDown, Checkbox].map((Component, i) => <Component key={i} questionInfo={...} />}